08.03
1芹关、看之前的2篇文章
08.04
1续挟、換服務(wù)器并配置
阿里云服務(wù)器創(chuàng)建鏡像備份
登陸控制臺(tái)--->實(shí)例--->鏡像創(chuàng)建--->導(dǎo)出
需要開通OSS,暫未完成
2侥衬、安裝做題需要的環(huán)境等
centOS安裝apt-get, 比較麻煩
告辭诗祸,退了
3跑芳、換成Ubuntu
但是,字體沒有配色直颅,看起來很難受博个。
08.05
1、解決沒有高亮顯示
https://blog.csdn.net/wzy1551368/article/details/79394001
sudo apt install gedit
發(fā)現(xiàn)是因?yàn)槠胀ㄙ~戶登陸了际乘,而不是管理員登陸坡倔。
sudo vim /etc/ssh/sshd_config
找到 #PermitRootLogin prohibit-password
, 改為yes
成功修改為root權(quán)限登陸!
2脖含、安裝所必須的工具
pwngdb
pwntool
3罪塔、題目:fastbin_attack-examples
32位文件,IDA打開
參考文章 https://www.anquanke.com/post/id/86286
其中fd,bk指針只用到了fd
攻擊:覆蓋堆頭养葵,fd指向任意地址征堪。
除此之外對(duì)于fastbin還存在double free,house of spirit等攻擊方式关拒。
輸入bins佃蚜,即可查看bins的內(nèi)容。
delete之后
使用unsortedbin
來泄漏libc的指針着绊。
tcachebins機(jī)制是新引入的谐算。
08.06
1、CTF特訓(xùn)營
-
程序保護(hù)機(jī)制
归露,重定位洲脂,重定位信息可寫,full relro 重定位信息不可寫剧包。
free的規(guī)則
tcache
重要結(jié)構(gòu)體:entry 和 pertheread_struct運(yùn)行代碼
malloc需要包含頭文件 stdlib.h
08.07
1恐锦、示例運(yùn)行
有strcpy函數(shù),需要用到 <string.h> 頭文件
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void target_func(){
printf("Hacked\n");
}
void show_info_A(char *info){
printf("%s\n",info);
}
struct struct_A{
int type;
int size;
char A_info[0x20];
void (*show_info_ptr)(char *);
};
struct struct_B{
int type;
int size;
char B_info[0x40];
};
void show_info(void *data, int type){
printf("in show_info:%d\n",type);
if(type == 0){
printf("in 0\n");
struct struct_A *struct_A_ptr = (struct struct_A*)data;
struct_A_ptr -> show_info_ptr(struct_A_ptr->A_info);
}
else if(type == 1){
printf("in 1\n");
struct struct_B *struct_B_ptr = (struct struct_B*)data;
printf("%s\n",struct_B_ptr->B_info);
}
}
int main(){
struct struct_A *var_a;
struct struct_B *var_b;
var_a = malloc(sizeof(struct struct_A));
var_a->type = 0;
strcpy(var_a->A_info,"A_info");
var_a->show_info_ptr = show_info_A;
var_a->size = strlen(var_a -> A_info);
var_b = malloc(sizeof(struct struct_B));
scanf("%d",&var_a ->type);
getchar();
gets(var_b->B_info);
var_b->size = strlen(var_b -> B_info);
show_info(var_a,var_a->type);
show_info(var_b,var_b->type);
return 0;
}
gdb中查看函數(shù)地址的方法:x 函數(shù)名
得到target_func函數(shù)的地址為 0x55555555481a
書中有一個(gè)錯(cuò)誤疆液,B對(duì)應(yīng)的是1一铅,如果想有錯(cuò)誤,應(yīng)該輸入0.
終端中堕油,雙擊g潘飘,回到函數(shù)最開始的位置。
思想:填充A_info部分馍迄,添加返回地址即可福也。但是沒成功。
2攀圈、unlink
有檢查,突破手段 freenote 或 stkof
源碼:修改指針峦甩。如果P的尺寸不在small_bin赘来,并且P前一塊用來指示的尺寸不為NULL现喳,assert兩次。
freenote
3犬辰、視頻b站
08.08
1嗦篱、b站視頻
objdump -d hacknote | less
cat /proc/26666 maps
ldd 程序
可以查看使用的libc是哪一個(gè)。
LD_LIBRARY_PATH
真實(shí)地址在 .got.plt里面
lay asm可以查看匯編代碼幌缝。
libcdb.com可以查找函數(shù)的對(duì)應(yīng)地址(概率成功)
08.09-08.10
1灸促、棧
64位,控制rax
rax = rdi
輸出
控制rcx
(1)strcpy涵卵, ecx = 輸入字符串(2)ecx為syscall的下一行地址(可以用來泄漏libc基址)
lay reg查看寄存器的值
08.11
1浴栽、編寫帶debug symbol 的libc
下載太慢,本機(jī)下載再上傳轿偎。
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" ../configure --prefix=/root/test/glibc-2.19/64
make報(bào)錯(cuò)
編譯命令改為:
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized -Wno-error" CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized -Wno-error" ../configure --prefix=/root/test/glibc-2.19/64
還是報(bào)錯(cuò)
/usr/bin/ld: /root/test/glibc-2.19/build/csu/crt1.o: relocation R_X86_64_32S against symbol `__libc_csu_fini' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/crtbegin.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a PIE object
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
../Rules:140: recipe for target '/root/test/glibc-2.19/build/iconv/iconvconfig' failed
make[2]: *** [/root/test/glibc-2.19/build/iconv/iconvconfig] Error 1
make[2]: Leaving directory '/root/test/glibc-2.19/iconv'
Makefile:213: recipe for target 'iconv/others' failed
make[1]: *** [iconv/others] Error 2
make[1]: Leaving directory '/root/test/glibc-2.19'
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 2
參考 https://sourceware.org/bugzilla/show_bug.cgi?id=20845
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" ../configure --prefix=/root/test/glibc-2.19/64 --disable-shared
還是報(bào)錯(cuò)典鸡,但是錯(cuò)誤比剛才少了一些
不編譯2.19了,編譯2.23版本
參考視頻和文章 http://www.reibang.com/p/1a966b62b3d4
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" ../configure --prefix=/root/glibc/glibc-2.23/64 --disable-shared
不行坏晦,改為
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized -Wno-error" \ CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized -Wno-error" \ ../configure --prefix=/root/glibc/glibc-2.23/64 --disable-shared
還是錯(cuò)誤,可能是版本太低,參考
https://developer.aliyun.com/article/620956
**中途安裝 patchelf **
參考 https://blog.csdn.net/qq_33873431/article/details/97751520
編譯環(huán)境比當(dāng)前系統(tǒng)版本要高瓣戚。
/root/glibc/glibc-2.23/build/nss/getent.o: In function `rpc_keys':
/root/glibc/glibc-2.23/nss/getent.c:685: undefined reference to `setrpcent'
/root/glibc/glibc-2.23/nss/getent.c:686: undefined reference to `getrpcent'
/root/glibc/glibc-2.23/nss/getent.c:688: undefined reference to `endrpcent'
/root/glibc/glibc-2.23/nss/getent.c:697: undefined reference to `getrpcbyname'
/root/glibc/glibc-2.23/nss/getent.c:695: undefined reference to `getrpcbynumber'
collect2: error: ld returned 1 exit status
../Rules:147: recipe for target '/root/glibc/glibc-2.23/build/nss/getent' failed
make[2]: *** [/root/glibc/glibc-2.23/build/nss/getent] Error 1
make[2]: Leaving directory '/root/glibc/glibc-2.23/nss'
Makefile:214: recipe for target 'nss/others' failed
make[1]: *** [nss/others] Error 2
make[1]: Leaving directory '/root/glibc/glibc-2.23'
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 2
查看版本root@VM-0-3-ubuntu:/lib64# strings ld-linux-x86-64.so.2 | grep GLIBC
可能只能下載相應(yīng)的版本撞蜂。。仓蛆。睁冬。
下載2.4版本的應(yīng)該沒錯(cuò)
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized -Wno-error" CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized -Wno-error" ../configure --prefix=/root/glibc/glibc-2.4/64 --disable-shared
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" ../configure --prefix=/root/glibc/glibc-2.4/64 --disable-shared
/root/glibc/glibc-2.23/64 --disable-shared
還是版本沒有,下載2.5試試
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" ../configure --prefix=/root/glibc/glibc-2.5/64 --disable-shared
下載2.3版本試試
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -w" ../configure --prefix=/root/glibc/glibc-2.3/64 --disable-shared
沒了原來版本2.3的提示了多律,但是說gcc的版本可能太低了痴突。
安裝最新版gcc的方法
需要gcc的版本是7.4.0,make的版本為4.1
不行不行不行
08.12
1狼荞、下載glibc源碼
官網(wǎng)下載較慢辽装,github上地址 https://github.com/jorinzou/glibc
2、分析
查看ldd版本
安裝docker
3相味、hacknote
編譯時(shí)加入-g拾积,就會(huì)帶上debuging symbol
chunk比malloc的內(nèi)存要大一點(diǎn)
lay src
參考 下圖,得到堆塊的內(nèi)容
top chunk
用來記錄可以使用丰涉,但是沒有分配的內(nèi)存 0x20d71
再malloc一些塊
地址頭部由290變?yōu)?d0拓巧,+0x40
內(nèi)存d71變?yōu)閐31 , -0x40
ltrace 會(huì)trace libc的function call
ltrace -e 'malloc+free' ./hacknote
chunk在使用的時(shí)候,fd bk沒有作用一死,可以存放data,free之后才有作用
p/x *(struct malloc_chunk*)0x555555756250
將內(nèi)存轉(zhuǎn)為chunk來查看
08.13
1肛度、b站視頻
使用malloc需要包含 <stdlib.h>
free掉p之后,按理說size的P位應(yīng)該為0,但是測試發(fā)現(xiàn)還是1
查看最開始free的chunk, fd指向main_arean部分
實(shí)驗(yàn)結(jié)果:main_arean是一個(gè)環(huán)狀
-
malloc會(huì)把剛剛釋放的給重新分配回來
08.14
1投慈、b站視頻
發(fā)現(xiàn)和視頻講解不一樣承耿,新malloc的是靠后的0x...4e0
查看bin結(jié)構(gòu)如下
這是由于新引入的tcachebins的結(jié)構(gòu)冠骄,新free的被放在最開頭的位置
可能是單鏈表的結(jié)構(gòu),bk的值都是0.
- 如果一個(gè)chunk后面是top chunk加袋,在free的時(shí)候會(huì)和后面的合并凛辣。如果它前面或者后面的沒有使用(not inuse),free的時(shí)候也會(huì)合并
2职烧、UAF
free掉的東西有機(jī)會(huì)再被利用扁誓,因?yàn)橹羔槢]有清空。
函數(shù)如下
#include <cstdio>
#include <cstdlib>
#include <cstring>
class A{
public:
virtual void print(){
puts("class A");
}
};
class B: public A{
public:
void print(){
puts("class B");
}
};
void sh(){
system("sh");
}
char buf[1024];
int main(){
setbuf(stdout,0,_IONBF,0);
A *p = new B(); //malloc
delete p; //free
fgets(buf,sizeof(buf),stdin);
char *q = strndup(buf); // malloc
p->print();
return 0;
}
08.17
1蚀之、b站視頻
上個(gè)程序分析
p首先地址是 0x602010
fd原本指向的是B的print
free掉之后原來指向的內(nèi)容就會(huì)清零
08.18
1蝗敢、b站視頻---uaf
strdup在復(fù)制的時(shí)候,64位很有可能00截?cái)唷?/p>
call函數(shù)的時(shí)候恬总,自己可以使用傳遞的第一個(gè)參數(shù)前普,是object本身。
想查看一個(gè)函數(shù)的地址壹堰,直接p 函數(shù)名
即可拭卿。
如果沒有直接的后門函數(shù),自己構(gòu)造printf贱纠,p->print會(huì)把p傳進(jìn)來
2峻厚、Fastbin corruption
尺寸小于0x80
單鏈表,只用fd谆焊,fd是指向下一個(gè)塊的指針惠桃。
重新malloc取塊時(shí),也是從頭部開始拿的辖试,因?yàn)槭菃捂湵?br>
自己也有一些檢查
關(guān)于double free:只檢查第一個(gè)chunk是否和要free的相同辜王,容易繞過。
08.19
???
08.20
???
08.21
1罐孝、fastbin
取出的chunk的size要正確
繞過:
- stack上的變數(shù)當(dāng)作size
- GOT上呐馆,如果函數(shù)沒有call過,通常地址為0x40莲兢,把0x40當(dāng)作size
接下來就會(huì)對(duì)任意地址進(jìn)行讀寫
08.23
1汹来、fastbin -- double free
程序如下
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void sh(char *cmd){
system(cmd);
}
int main(){
// setbuf(stdout, 0, _IONBF, 0);
int cmd,idx,sz;
char *ptr[10];
memset(ptr,0,sizeof(ptr));
puts("1.malloc + gets\n2.free\n3.puts");
while(1){
printf("> ");
scanf("%d %d", &cmd, &idx);
idx %= 10;
if (cmd == 1){
scanf("%d%*c", &sz);
ptr[idx] = malloc(sz);
gets(ptr[idx]);
}
else if (cmd == 2){
free(ptr[idx]);
}
else if (cmd == 3){
puts(ptr[idx]);
}
else exit(0);
}
return 0;
}
輸入的是cmd,idx
-
如果free的部分是空的,就什么都不做改艇。
檢查不太好
objdump -d fastbin > d1
ps au
查看進(jìn)程id
08.23
1收班、fastbin
heap起始的位置是 0x555555756000
結(jié)束的位置是
heap2- 32min
參考視頻 https://www.bilibili.com/video/BV1op4y1D7e9?from=search&seid=9463446650216238443
向后合并是 把前一個(gè)塊與此塊合并。
- 理解glibc malloc
參考 https://sploitfun.wordpress.com/2015/02/10/understanding-glibc-malloc/
1谒兄、b站視頻 heap
需要glibc摔桦,下載
wget https://ftp.gnu.org/gnu/libc/glibc-2.19.tar.gz
強(qiáng)網(wǎng)先鋒AP
步驟大概就是:覆蓋,泄漏puts地址承疲,找到基址酣溃,
參考
https://prowes5.github.io/2019/05/27/2019強(qiáng)網(wǎng)杯部分writeup/
https://www.anquanke.com/post/id/179386#h2-10
http://blog.leanote.com/post/xp0int/[Pwn]-強(qiáng)網(wǎng)先鋒-AP-mf
1瘦穆、搭建CTF-PWN環(huán)境
CTF特訓(xùn)營
做題網(wǎng)址
http://pwnable.kr/play.php
https://www.jarvisoj.com/login
https://www.ctfhub.com/#/index