malloc位于栈上的chunk
0x00 Background笔者打nssctf上的一题打了两天才通,收获颇多,记录一下。pwn攻击不应该孤立的看。换句话说,要无所不用其极,哪种攻击好使就用哪种。现在就来浅浅分析一下在堆中对栈的攻击。(手法很多,后面慢慢学慢慢补充吧 0x01 利用environ变量以下调试以[NSSRound#21Basic]want_girlfriend(glibc2.35)的程序来演示。在linux环境下,程序存在一个全局变量(char**)environ,位于libc数据段,与libcbase存在固定偏移 1environ_addr=libcbase+libc.sym["environ"] environ指向一个指针数组,数组中每个指针指向一个环境变量字符串,而环境变量字符串是位于栈区的。 1234pwndbg> p &environ$1 = (<data variable, no debug info> *) 0x7ffff7e22200 <environ>pwndbg> x/gx...
不同版本下glibc有关堆的管理和保护
0x00记录一下不同版本glibc下的堆管理保护机制的变化(开个坑,以后慢慢记录补充先贴上几篇参考博客不同版本glibc的堆管理和新增保护机制 - Luexpglibc各版本的堆保护 | jkilopu’s blogGlibc中堆管理的变化 | 白里个白Glibc高版本堆利用方法总结 - LynneHuan - 博客园然后ubuntu和glibc不同版本的对应关系 12345678910111213ubuntu-libc version2.23=“16.04”2.24=“17.04”2.26=“17.10”2.27=“18.04”2.28=“18.10”2.29=“19.04”2.30=“19.10”2.31=“20.04”2.32=“20.10”2.33=“21.04”2.34=“22.04” 0x01 关于tcachebins在glibc2.26+,引入了tcachebins有两个比较关键的函数tcache_get()和tcache_put()(以下为glibc2.28中的源码) 1234567891011121314151617181920static...
劫持tcache_perthread_struct
0x00 关于tcache_perthread_structtcache 是 glibc 2.26 (ubuntu 17.10) 之后引入的一种技术,目的是提升堆管理的性能,与 fastbin 类似。 tcache 引入了两个新的结构体,tcache_entry和 tcache_perthread_struct 。两个结构体源码如下 12345678910typedef struct tcache_entry{ struct tcache_entry *next;} tcache_entry;typedef struct tcache_perthread_struct{ char counts[TCACHE_MAX_BINS];//0x40 tcache_entry *entries[TCACHE_MAX_BINS];//0x40} tcache_perthread_struct; 12TCACHE_MAX_BINS:# define TCACHE_MAX_BINS ...
关于fastbin attack与unsortedbin leak
0x00以三道循序渐进的题目为例来分析吧。 0x01 hitcontraining_uaf / hacknote复盘/uaf/heapoverflow题目源码如下 123456789101112131415161718192021222324252627282930313233343536373839404142int __cdecl __noreturn main(int argc, const char **argv, const char **envp){ int v3; // eax char buf[4]; // [esp+0h] [ebp-Ch] BYREF int *p_argc; // [esp+4h] [ebp-8h] p_argc = &argc; setvbuf(stdout, 0, 2, 0); setvbuf(stdin, 0, 2, 0); while ( 1 ) { while ( 1 ) { menu(); read(0, buf,...
LitCTF2025
0x002025-6-30:犯懒了,仅仅复现了nc这道题目2025-9-21补:wmctf强度太大,回过头来复现一下这个,放松一下身心 0x01 nc把附件拖进ida发现得出了我看不懂的一坨玩意在re手的指导下,直接用vscode打开得到了一段python代码,如下 12345678910111213#!/bin/python3import osprint("input your command")blacklist = ['cat','ls',' ','cd','echo','<','${IFS}','sh','\\']while True: command = input() for i in blacklist: if i in command: exit(0) ...
御网杯2025
Canary复盘/ret2text/canary/伪随机数题目源码如下 123456__int64 __fastcall main(__int64 a1, char **a2, char **a3){ sub_401296(); sub_4013C7(); return 0LL;} 两个函数分别如下 12345678910111213141516171819void sub_401296(){ int v0; // eax int fd; // [rsp+Ch] [rbp-4h] setbuf(stdin, 0LL); setbuf(stdout, 0LL); setbuf(stderr, 0LL); fd = open("/dev/urandom", 0); if ( fd == -1 ) { printf("can't open /dev/urandom"); exit(-1); } read(fd,...
XYCTF2025
Ret2libc’s Revenge复现/ret2libc/全缓冲源码如下 12345678910111213141516171819202122232425262728293031323334353637int __fastcall main(int argc, const char **argv, const char **envp){ init(argc, argv, envp); puts("Ret2libc's Revenge"); revenge(); return 0;}__int64 init(){ setvbuf(stdin, 0LL, 2, 0LL); setvbuf(stdout, 0LL, 0, 0LL); setvbuf(stderr, 0LL, 0, 0LL); return 0LL;}__int64 revenge(){ int v0; // eax char v2[528]; // [rsp+0h] [rbp-220h] ...
TGCTF2025
签到ret2libc简单的ret2libc,源码如下 123456789101112131415int __fastcall main(int argc, const char **argv, const char **envp){ char v4[112]; // [rsp+0h] [rbp-70h] BYREF setbuf(stdin, 0LL); setbuf(_bss_start, 0LL); setbuf(stderr, 0LL); puts( "As a student who has been learning pwn for half a year\n" "basic ROP is an essential skill that everyone should master. \n" "Therefore, hurry up and complete the check-in. \n" "Welcome to the Hangzhou Normal...
WHUCTF2025
repeater_handout复盘/ret2libc题目源码 1234567891011121314151617181920212223242526272829__int64 __fastcall main(int a1, char **a2, char **a3){ int v4; // [rsp+Ch] [rbp-24h] BYREF char buf[24]; // [rsp+10h] [rbp-20h] BYREF unsigned __int64 v6; // [rsp+28h] [rbp-8h] v6 = __readfsqword(0x28u); setvbuf(stdin, 0LL, 2, 0LL); setvbuf(stdout, 0LL, 2, 0LL); setvbuf(stderr, 0LL, 2, 0LL); puts( "When Siesta was chatting with Rin-chan, he was so engrossed that he couldn't hear...