<summary><strong>Leer AWS-hacking vanaf nul tot held met</strong><ahref="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
* Als je je **bedrijf wilt adverteren in HackTricks** of **HackTricks in PDF wilt downloaden**, bekijk dan de [**ABONNEMENTSPAKKETTEN**](https://github.com/sponsors/carlospolop)!
* Koop de [**officiële PEASS & HackTricks-merchandise**](https://peass.creator-spring.com)
* **Sluit je aan bij de** 💬 [**Discord-groep**](https://discord.gg/hRep4RUj7f) of de [**telegram-groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
* **Deel je hacktrucs door PR's in te dienen bij de** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github-repos.
Dus, in feite is het nodig om de string `/bin/sh` ergens te schrijven en vervolgens de `syscall` uit te voeren (met inachtneming van de padding die nodig is om de stack te controleren).
ROP is a technique used in exploitation to bypass security measures like DEP (Data Execution Prevention) and ASLR (Address Space Layout Randomization). It involves chaining together small pieces of code, known as gadgets, to perform malicious actions.
##### Syscall
A syscall is a way for a program to request services from the operating system. In Linux, syscalls are identified by a number, and the parameters for the syscall are passed in registers.
The execv syscall is used to execute a program in Linux. It takes two arguments: the path to the program and an array of strings representing the program's arguments.
##### ROP + Syscall + Execv
To execute a program using ROP, we need to find gadgets that perform the necessary syscalls and set the appropriate registers. We can then chain these gadgets together to create a ROP chain that calls execv with the desired program and arguments.
##### Example
Here is an example of a ROP chain that calls execv to execute the "/bin/sh" program:
1. Find gadgets that set the registers for the execv syscall.
2. Find a gadget that sets the EAX register to the syscall number for execv.
3. Find a gadget that sets the EBX register to the address of the "/bin/sh" string.
4. Find a gadget that sets the ECX register to the address of the argument array.
5. Find a gadget that sets the EDX register to 0 (no environment variables).
6. Find a gadget that performs the syscall instruction.
7. Chain these gadgets together in the correct order, setting the registers and performing the syscall.
By carefully constructing the ROP chain, we can execute arbitrary programs with arbitrary arguments, giving us full control over the system.
Hierdie tegniek maak gebruik van Return-Oriented Programming (ROP) in kombinasie met die Syscall-instruksie en die execv-sisteemoproep om 'n uitvoerbare lêer uit te voer op 'n 64-bits Linux-stelsel.
-`mprotect`: Hierdie funksie sal ons toelaat om die uitvoerbare geheuegebied te verander na lees-, skryf- en uitvoerbare (rwx) toestand.
-`read`: Hierdie funksie sal ons toelaat om die uitvoerbare lêer in die geheue te lees.
-`execve`: Hierdie funksie sal ons toelaat om die uitvoerbare lêer uit te voer.
##### Stap 2: Bou die ROP-ketting
Ons sal die volgende stappe volg om die ROP-ketting te bou:
1. Kry die adres van die `mprotect`-funksie in die geheue.
2. Kry die adres van die `read`-funksie in die geheue.
3. Kry die adres van die `execve`-funksie in die geheue.
4. Kry die adres van die uitvoerbare lêer in die geheue.
5. Bou die ROP-ketting deur die funksie-adresse en die nodige argumente in die regte volgorde te stapel.
##### Stap 3: Voer die ROP-ketting uit
Nadat die ROP-ketting gebou is, kan ons dit uitvoer deur die Syscall-instruksie te gebruik. Hier is die stappe wat ons moet volg:
1. Stel die regsiters korrek in vir die Syscall-instruksie.
2. Voer die Syscall-instruksie uit.
##### Stap 4: Verifieer die uitvoering
Om te verseker dat die uitvoering suksesvol was, kan ons die uitvoer van die uitvoerbare lêer monitor.
Met hierdie tegniek kan ons 'n uitvoerbare lêer uitvoer op 'n 64-bits Linux-stelsel deur gebruik te maak van ROP, die Syscall-instruksie en die execv-sisteemoproep.
In hierdie voorbeeld sal ons 'n basiese ROP (Return-Oriented Programming) tegniek gebruik om die `execv` stelseloproep in 'n Linux omgewing uit te voer.
First, we need to find the addresses of the gadgets we will use in our ROP chain. We can use tools like `ROPgadget` or `ropper` to search for gadgets in the binary.
Eerstens moet ons die adresse van die gadgets wat ons in ons ROP-ketting sal gebruik, vind. Ons kan gereedskap soos `ROPgadget` of `ropper` gebruik om gadgets in die binêre lêer te soek.
Once we have the addresses, we can start building our ROP chain. The ROP chain will consist of the addresses of the gadgets we want to use, followed by the arguments for the `execv` system call.
Sodra ons die adresse het, kan ons begin om ons ROP-ketting te bou. Die ROP-ketting sal bestaan uit die adresse van die gadgets wat ons wil gebruik, gevolg deur die argumente vir die `execv` stelseloproep.
We will need gadgets that perform the following actions:
1. Load the address of the `/bin/sh` string into a register.
2. Load the address of the `execv` function into a register.
3. Load the arguments for the `execv` function into registers.
4. Call the `execv` function.
Ons sal gadgets benodig wat die volgende aksies uitvoer:
1. Laai die adres van die `/bin/sh` string in 'n register.
2. Laai die adres van die `execv` funksie in 'n register.
3. Laai die argumente vir die `execv` funksie in registers.
4. Roep die `execv` funksie aan.
Once we have our ROP chain, we can trigger the vulnerability to execute our ROP chain and ultimately the `execv` system call.
Sodra ons ons ROP-ketting het, kan ons die kwesbaarheid aktiveer om ons ROP-ketting en uiteindelik die `execv` stelseloproep uit te voer.
<summary><strong>Leer AWS-hacking van nul tot held met</strong><ahref="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
* As jy jou **maatskappy geadverteer wil sien in HackTricks** of **HackTricks in PDF wil aflaai**, kyk na die [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Kry die [**amptelike PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Ontdek [**The PEASS Family**](https://opensea.io/collection/the-peass-family), ons versameling eksklusiewe [**NFTs**](https://opensea.io/collection/the-peass-family)
* **Sluit aan by die** 💬 [**Discord-groep**](https://discord.gg/hRep4RUj7f) of die [**telegram-groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
* **Deel jou hacking-truuks deur PR's in te dien by die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github-repos.