Skip to content

Commit

Permalink
fix bug in patchelfForZsh and update md style
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMaDev committed Jul 30, 2024
1 parent c5b4114 commit 48a27d7
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 39 deletions.
6 changes: 3 additions & 3 deletions source/_posts/isctf2023/abstract_shellcode.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: isctf2023 - abstract shellcode
date: 2023/12/2 20:00:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:28:00
tags:
- shellcode
excerpt: 通过分析64位程序的shellcode,利用read和execve实现远程shell的获取。
Expand All @@ -26,11 +26,11 @@ ghidra分析为64位程序

下文有shellcode的详细解释

## 踩过的坑

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

## EXPLOIT

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

## 踩过的坑

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

## EXPLOIT

Expand Down
7 changes: 3 additions & 4 deletions source/_posts/isctf2023/touch_file2.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: isctf2023 - touch file 2
date: 2023/12/5 12:00:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:28:00
tags:
- heap - tcache
- libc2.31
Expand All @@ -24,16 +24,15 @@ glibc: 2.31
再进行tcache dup,把`__free_hook`写上system,最后给一个chunk上写上/bin/sh,
free它就能拿到shell

## 踩过的坑

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

## EXPLOIT

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

{% notel purple 踩过的坑 %}
{% notel green fa-arrow-right tips %}
1. 32位的int 0x80好像不能用,就算设置rax=0xb,也无法正常打开shell
2. 不要用ascii转换器,22字节的shellcode可以转出76字节来
{% endnotel %}
Expand Down
10 changes: 5 additions & 5 deletions source/_posts/moectf2023/feedback.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: moectf2023 - feedback
date: 2023/9/27 12:00:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:28:00
tags:
- IO arb write
excerpt: 利用`_IO_FILE`结构体漏洞,通过修改stdout指针实现读取flag。
Expand Down Expand Up @@ -53,8 +53,7 @@ puts, sprintf, printf等包装函数,最后都会调用write,可以对stdout
会打印`_IO_write_base`到`_IO_write_ptr`范围内的字符;初始化后`_IO_write_*`
会指向结构体中的`_shortbuf`,通过覆盖最后一个字节,可以将base指向`_chain`
## 踩过的坑
{% notel blue fa-arrow-right tips %}
一开始在我本地上跑的时候,flag是无法写入的:
read函数返回-1(val of rax),使用`p *__errno_location()`查询errno得知,
14: Bad Address,本身读入的地址就没有w权限
Expand All @@ -68,12 +67,13 @@ Arch Linux可以直接pacman(yay)安装patchelf哦
gdb中要重启程序不需要q,先kill再run/start即可
```shell
patchelf patchelf --set-interpreter ./libs/ld-2.31.so --replace-needed libc.so.6 ./libs/libc-2.31.so feedback
```sh
patchelf --set-interpreter ./libs/ld-2.31.so --replace-needed libc.so.6 ./libs/libc-2.31.so feedback
chmod +x ./libs/* # 一定要+x!不然没有权限执行
```

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

## 解题思路

Expand Down
6 changes: 4 additions & 2 deletions source/_posts/moectf2023/format_level3.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: moectf2023 - format level3
date: 2023/9/26 12:00:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:28:00
tags:
- noob
excerpt: 通过利用ebp间接改写返回地址,成功利用后门漏洞解决format level3题目。
Expand All @@ -16,9 +16,11 @@ ghidra分析为32位程序

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

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

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

## EXPLOIT

Expand Down
5 changes: 3 additions & 2 deletions source/_posts/newstar2023/W2_shellcode_revenge.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: newstar2023 week2 - shellcode revenge
date: 2023/10/4 12:00:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:28:00
tags:
- shellcode
thumbnail: /assets/newstar2023/regs.png
Expand Down Expand Up @@ -78,11 +78,12 @@ rcx + 'Z': \0 ; store rbx later
```

最后shellcode长度:**90字节**
## 踩过的坑

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

```python
def toHex(s: str):
Expand Down
6 changes: 3 additions & 3 deletions source/_posts/newstar2023/W3_puts_or_system.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: newstar2023 week3 - puts or system
date: 2023/10/12 12:00:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:28:00
tags:
- noob
excerpt: 通过格式化字符串漏洞,将程序中的puts调用替换为system调用,成功获取shell。
Expand All @@ -19,10 +19,10 @@ ghidra分析为64位程序

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

## 踩过的坑

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

## EXPLOIT

Expand Down
1 change: 0 additions & 1 deletion source/_posts/newstar2023/W4_ezheap.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ fastbin: head -> 7 -> 8
"""

addn(9, 1024) #0 huge chunk to trigger malloc consolidate
updated: 2024/7/25 12:34:56
"""
bins now:
inuse: ...
Expand Down
6 changes: 3 additions & 3 deletions source/_posts/newstar2023/W4_message_board.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: newstar2023 week4 - message board
date: 2023/10/20 12:00:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:28:00
tags:
- fmt-string
excerpt: 利用栈初始化和one_gadget漏洞,成功在msgboard程序中获取shell。
Expand All @@ -19,15 +19,15 @@ scanf也只能修改任意地址一次,又要怎么做?

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

## 踩过的坑

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

## EXPLOIT

Expand Down
6 changes: 3 additions & 3 deletions source/_posts/newstar2023/W5_no_ouput.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: newstar2023 week5 - no ouput
date: 2023/10/23 12:00:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:28:00
tags:
- stack pivot
- 1-digit guess
Expand All @@ -27,8 +27,7 @@ ghidra分析为64位程序
而改是一个字节一个字节改的,因此`read & 0xF000`这4位是赌的,每次有1/16的概率能中,
并不是执行脚本就能一次打下来的

## 踩过的坑

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

## EXPLOIT

Expand Down
1 change: 0 additions & 1 deletion source/_posts/ningbo2024/minho.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def payload(lo:int):
p64(0) + p64(0x21) + p64(libcBase + arena + 0x60)*2 + # shrink chunk size from 0xcf1 to 0x21
p64(0x20) + p64(0x10) + p64(0) + p64(0x11)) # 2 lookout chunks to make forced chunk legal
malloc0x1000() # trigger malloc_consolidate()
updated: 2024/7/25 12:34:56

# Step 4, force a small bin chain to control tcache
heap = heapBase + 0x310
Expand Down
7 changes: 3 additions & 4 deletions source/_posts/patchelfForZsh.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 修复zsh上patchelf自动补全的错误
date: 2024/5/8 22:40:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:53:00
tags:
- tricks
- not-ctf
Expand All @@ -19,10 +19,10 @@ thumbnail: /images/patchelfFix.png

## 前情提要

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

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

## 修复
Expand Down Expand Up @@ -62,7 +62,6 @@ curl -o /path/to/your/_patchelf https://raw.githubusercontent.com/RocketMaDev/pa
放在`~/.zshrc`中,方便在patchelf更新的时候再次覆盖脚本
```zsh
update_patchelf() {
updated: 2024/7/25 12:34:56
sudo curl -o /usr/share/zsh/site-functions/_patchelf "https://raw.githubusercontent.com/RocketMaDev/patchelf/master/completions/zsh/_patchelf"
unfunction _patchelf && autoload -U _patchelf
}
Expand Down
6 changes: 3 additions & 3 deletions source/_posts/practice/stackremove.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 赛博协会训练营 - stackremove
date: 2023/9/22 12:00:00
updated: 2024/7/25 12:34:56
updated: 2024/7/30 10:28:00
tags:
- noob
excerpt: 通过栈迁移和ret2libc利用,成功破解`stackremove`程序。
Expand All @@ -22,10 +22,10 @@ ghidra分析为64位程序

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

## 踩过的坑

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

## EXPLOIT

Expand Down

0 comments on commit 48a27d7

Please sign in to comment.