Skip to content

Commit 48a27d7

Browse files
committedJul 30, 2024·
fix bug in patchelfForZsh and update md style
1 parent c5b4114 commit 48a27d7

14 files changed

+38
-39
lines changed
 

‎source/_posts/isctf2023/abstract_shellcode.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: isctf2023 - abstract shellcode
33
date: 2023/12/2 20:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- shellcode
77
excerpt: 通过分析64位程序的shellcode,利用read和execve实现远程shell的获取。
@@ -26,11 +26,11 @@ ghidra分析为64位程序
2626

2727
下文有shellcode的详细解释
2828

29-
## 踩过的坑
30-
29+
{% note tip fa-arrow-right %}
3130
read的第三个参数`count`有最大值`SSIZE_MAX(0x7ffff000 on Linux)`
3231
超过这个值是依赖于实现的,当我随便找了一个超大数字时,我用的Arch Linux可以成功read,
3332
Ubuntu就不行,害得我一开始连远端就寄,还得开虚拟机试试(毕竟是内核存在差别)
33+
{% endnote %}
3434

3535
## EXPLOIT
3636

‎source/_posts/isctf2023/fries.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: isctf2023 - fries
33
date: 2023/12/4 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- noob
77
excerpt: 涉及格式化字符串和ret2libc攻击,通过泄露栈和libc地址并利用one_gadget实现远程shell。
@@ -17,10 +17,10 @@ ghidra分析为64位程序
1717
这道题考察格式化字符串+ret2libc,共有8次机会,可以先leak栈地址和libc地址,
1818
再把返回地址写成打开shell,此处使用one_gadget可以只利用一次返回完成攻击
1919

20-
## 踩过的坑
21-
20+
{% note tip fa-arrow-right %}
2221
本地能过的脚本,远端换了多少ogg就是不行,最后发现是栈上内容不一样!
2322
下次还是先patchelf把libc打成目标的再本地调试吧(一开始偷懒,本地没patch)
23+
{% endnote %}
2424

2525
## EXPLOIT
2626

‎source/_posts/isctf2023/touch_file2.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: isctf2023 - touch file 2
33
date: 2023/12/5 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- heap - tcache
77
- libc2.31
@@ -24,16 +24,15 @@ glibc: 2.31
2424
再进行tcache dup,把`__free_hook`写上system,最后给一个chunk上写上/bin/sh,
2525
free它就能拿到shell
2626

27-
## 踩过的坑
28-
27+
{% notel green fa-arrow-right tips %}
2928
1. strncpy函数会将size中未输入的部分全部填0,并且复制时是'\0'截断的!这点要注意
3029
2. 这题附件给了ld,给了libc,但是libstdc++之类的其他依赖都没给,这时候借助docker,
3130
下载一个ubuntu容器可以快速解决问题(主要是本地的libcstdc++依赖高版本libc)
3231
3. 手动释放一个chunk到unsorted bin中需要满足对应的后一个chunk处(&chunk + size)
3332
的P位设为1
3433
4. 当getline得到一个超长输入时,会分配一个chunk,用完后释放,可以考虑写入大量垃圾字符,
3534
来触发`malloc_consolidate`(不是用在这题)
36-
updated: 2024/7/25 12:34:56
35+
{% endnotel %}
3736

3837
## EXPLOIT
3938

‎source/_posts/moectf2023/changeable_shellcode.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: moectf2023 - changeable shellcode
33
date: 2023/9/24 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- noob
77
excerpt: 通过分析64位程序的shellcode,利用特定内存区域绕过检测并成功打开shell。
@@ -23,7 +23,7 @@ gdb `vmmap`查看发现该区域可读写执行
2323
然后跳转到写了syscall`|05|0f|`的地址,
2424
并且除了syscall以外的指令要写到最简以免长度超限
2525

26-
{% notel purple 踩过的坑 %}
26+
{% notel green fa-arrow-right tips %}
2727
1. 32位的int 0x80好像不能用,就算设置rax=0xb,也无法正常打开shell
2828
2. 不要用ascii转换器,22字节的shellcode可以转出76字节来
2929
{% endnotel %}

‎source/_posts/moectf2023/feedback.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: moectf2023 - feedback
33
date: 2023/9/27 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- IO arb write
77
excerpt: 利用`_IO_FILE`结构体漏洞,通过修改stdout指针实现读取flag。
@@ -53,8 +53,7 @@ puts, sprintf, printf等包装函数,最后都会调用write,可以对stdout
5353
会打印`_IO_write_base`到`_IO_write_ptr`范围内的字符;初始化后`_IO_write_*`
5454
会指向结构体中的`_shortbuf`,通过覆盖最后一个字节,可以将base指向`_chain`
5555
56-
## 踩过的坑
57-
56+
{% notel blue fa-arrow-right tips %}
5857
一开始在我本地上跑的时候,flag是无法写入的:
5958
read函数返回-1(val of rax),使用`p *__errno_location()`查询errno得知,
6059
14: Bad Address,本身读入的地址就没有w权限
@@ -68,12 +67,13 @@ Arch Linux可以直接pacman(yay)安装patchelf哦
6867
6968
gdb中要重启程序不需要q,先kill再run/start即可
7069
71-
```shell
72-
patchelf patchelf --set-interpreter ./libs/ld-2.31.so --replace-needed libc.so.6 ./libs/libc-2.31.so feedback
70+
```sh
71+
patchelf --set-interpreter ./libs/ld-2.31.so --replace-needed libc.so.6 ./libs/libc-2.31.so feedback
7372
chmod +x ./libs/* # 一定要+x!不然没有权限执行
7473
```
7574

7675
patch后gdb调试发现这时flag就会放到一个匿名内存段,不会崩溃了
76+
{% endnotel %}
7777

7878
## 解题思路
7979

‎source/_posts/moectf2023/format_level3.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: moectf2023 - format level3
33
date: 2023/9/26 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- noob
77
excerpt: 通过利用ebp间接改写返回地址,成功利用后门漏洞解决format level3题目。
@@ -16,9 +16,11 @@ ghidra分析为32位程序
1616

1717
和level2类似,存在后门,但是输入的str放到了.bss上
1818

19-
踩过的坑:16字节还想把栈迁移到.bss上?直接爆了(栈上的空间本来也不够)
19+
{% note tip fa-arrow-right %}
20+
16字节还想把栈迁移到.bss上?直接爆了(栈上的空间本来也不够)
2021

2122
正解:通过ebp+4来利用ebp间接改写返回地址
23+
{% endnote %}
2224

2325
## EXPLOIT
2426

‎source/_posts/newstar2023/W2_shellcode_revenge.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: newstar2023 week2 - shellcode revenge
33
date: 2023/10/4 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- shellcode
77
thumbnail: /assets/newstar2023/regs.png
@@ -78,11 +78,12 @@ rcx + 'Z': \0 ; store rbx later
7878
```
7979

8080
最后shellcode长度:**90字节**
81-
## 踩过的坑
8281

82+
{% notel green fa-arrow-right tips %}
8383
1. gdb在调试shellcode的时候建议用si,ni会直接运行到底
8484
2. 网上资料可能不全,需要自己摸索,比如'40'就是自己反汇编才知道的
8585
3. 字符间换来换去还挺麻烦的,用用下面的函数
86+
{% endnotel %}
8687

8788
```python
8889
def toHex(s: str):

‎source/_posts/newstar2023/W3_puts_or_system.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: newstar2023 week3 - puts or system
33
date: 2023/10/12 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- noob
77
excerpt: 通过格式化字符串漏洞,将程序中的puts调用替换为system调用,成功获取shell。
@@ -19,10 +19,10 @@ ghidra分析为64位程序
1919

2020
由于程序relro保护为partial,因此可以直接将`puts@got`地址改为system地址即可
2121

22-
## 踩过的坑
23-
22+
{% note tip fa-arrow-right %}
2423
%n系列写地址输出过的字符是**累计的**,所以计算失误就会导致攻击失败,
2524
因此可以把小的数字放在前面,大的数字放在后面,方便计算
25+
{% endnote %}
2626

2727
## EXPLOIT
2828

‎source/_posts/newstar2023/W4_ezheap.md

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ fastbin: head -> 7 -> 8
101101
"""
102102

103103
addn(9, 1024) #0 huge chunk to trigger malloc consolidate
104-
updated: 2024/7/25 12:34:56
105104
"""
106105
bins now:
107106
inuse: ...

‎source/_posts/newstar2023/W4_message_board.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: newstar2023 week4 - message board
33
date: 2023/10/20 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- fmt-string
77
excerpt: 利用栈初始化和one_gadget漏洞,成功在msgboard程序中获取shell。
@@ -19,15 +19,15 @@ scanf也只能修改任意地址一次,又要怎么做?
1919

2020
分别利用栈初始化和one_gadget即可
2121

22-
## 踩过的坑
23-
22+
{% notel green fa-arrow-right tips %}
2423
1. libcBase并不是无中生有,而是在栈上存在未初始化的`_IO_2_1_stderr_`
2524
2. 数字会覆盖到栈上;垃圾字符会导致scanf一直输入不了;而'+'能使scanf跳过输入,
2625
不覆盖栈内容
2726
3. ELF里的symbols不止可以找函数,找stderr这样的标签都是可以的
2827
4. got可写,那么可以利用one_gadget来使一个函数直接运行打开shell(但是要注意限制条件)
2928
5. 注意got里的函数是不可写的,只有.got.plt里的函数可写
3029
6. one_gadget在本地不一定是可用的,在我的电脑上就没开起来(但是验证了可行性)
30+
{% endnotel %}
3131

3232
## EXPLOIT
3333

‎source/_posts/newstar2023/W5_no_ouput.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: newstar2023 week5 - no ouput
33
date: 2023/10/23 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- stack pivot
77
- 1-digit guess
@@ -27,8 +27,7 @@ ghidra分析为64位程序
2727
而改是一个字节一个字节改的,因此`read & 0xF000`这4位是赌的,每次有1/16的概率能中,
2828
并不是执行脚本就能一次打下来的
2929

30-
## 踩过的坑
31-
30+
{% notel green fa-arrow-right tips %}
3231
1. write函数是对系统调用的封装,因此开栈不大,可以放心迁移
3332
2. system执行的参数在这题只能是libc里的shstr,在.bss上捏的就不行,
3433
网上也搜不到结果,请懂的师傅发个discussion
@@ -38,6 +37,7 @@ ghidra分析为64位程序
3837
因此需要用next包裹,如`next(elf.search(str))`
3938
5. 看准时间提交...虽然比赛是周日晚9点更新题目,但是结束是在早上9点...
4039
做出来了没提交上:(
40+
{% endnotel %}
4141

4242
## EXPLOIT
4343

‎source/_posts/ningbo2024/minho.md

-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ def payload(lo:int):
213213
p64(0) + p64(0x21) + p64(libcBase + arena + 0x60)*2 + # shrink chunk size from 0xcf1 to 0x21
214214
p64(0x20) + p64(0x10) + p64(0) + p64(0x11)) # 2 lookout chunks to make forced chunk legal
215215
malloc0x1000() # trigger malloc_consolidate()
216-
updated: 2024/7/25 12:34:56
217216

218217
# Step 4, force a small bin chain to control tcache
219218
heap = heapBase + 0x310

‎source/_posts/patchelfForZsh.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 修复zsh上patchelf自动补全的错误
33
date: 2024/5/8 22:40:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:53:00
55
tags:
66
- tricks
77
- not-ctf
@@ -19,10 +19,10 @@ thumbnail: /images/patchelfFix.png
1919

2020
## 前情提要
2121

22-
早在21年,**@Y7n05h**[尝试为zsh增加补全支持](https://github.com/NixOS/patchelf/issues/310)
22+
早在21年, **@Y7n05h**[尝试为zsh增加补全支持](https://github.com/NixOS/patchelf/issues/310)
2323
但随着他不再使用patchelf,他也停止了补全脚本的编写
2424

25-
23年,**@Freed-Wu**接过了任务,完成了补全脚本并提交了PR,但是他的脚本并不完全正确,
25+
23年, **@Freed-Wu**接过了任务,完成了补全脚本并提交了PR,但是他的脚本并不完全正确,
2626
导致了zsh无法正确补全
2727

2828
## 修复
@@ -62,7 +62,6 @@ curl -o /path/to/your/_patchelf https://raw.githubusercontent.com/RocketMaDev/pa
6262
放在`~/.zshrc`中,方便在patchelf更新的时候再次覆盖脚本
6363
```zsh
6464
update_patchelf() {
65-
updated: 2024/7/25 12:34:56
6665
sudo curl -o /usr/share/zsh/site-functions/_patchelf "https://raw.githubusercontent.com/RocketMaDev/patchelf/master/completions/zsh/_patchelf"
6766
unfunction _patchelf && autoload -U _patchelf
6867
}

‎source/_posts/practice/stackremove.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 赛博协会训练营 - stackremove
33
date: 2023/9/22 12:00:00
4-
updated: 2024/7/25 12:34:56
4+
updated: 2024/7/30 10:28:00
55
tags:
66
- noob
77
excerpt: 通过栈迁移和ret2libc利用,成功破解`stackremove`程序。
@@ -22,10 +22,10 @@ ghidra分析为64位程序
2222

2323
具体过程讲解可以看newstar2023中的`stack_migration`Writeup
2424

25-
## 踩过的坑
26-
25+
{% notel green fa-arrow-right tips %}
2726
1. `scanf`中的函数会执行`movaps ..., xmm0`,也会检查rsp!下次见到这个指令就要多加一个ret
2827
2. 本地调试找的main函数获取pieBase,结果一连接,崩了,一检查发现pieBase不对,在栈上找了一个其他函数
28+
{% endnotel %}
2929

3030
## EXPLOIT
3131

0 commit comments

Comments
 (0)
Please sign in to comment.