0%

ORW 初识

ORW类题目是指程序开了沙箱保护,禁用了一些函数的调用(如 execve等),使得我们并不能正常 get shell,只能通过ROP的方式调用open, read, write的来读取并打印flag 内容

栈迁移初识

  • 当我们栈溢出可用字节较少, 可以考虑进行栈迁移
  • 程序开启了 PIE 保护机制,栈地址未知,我们可以将栈劫持到已知的地址
  • 其它漏洞难以利用,我们需要进行转换,比如说将栈劫持到堆空间,从而在堆上写 rop 及进行堆漏洞利用

让我们来深入了解 leaveret 指令

前言

  • PIE(Position Independent Executable)和ASLR(Address Space Layout Randomization)是现代操作系统中常用的安全机制。通过随机化程序的内存布局,PIE和ASLR可以有效地防止攻击者利用已知的内存地址进行攻击。

ALSR 安全保护等级可以使用如下命令查看:

前言

Cancary 是一种安全加固保护机制,通过对程序栈底插入一段随机的字节串,来校验当前程序是否被栈溢出

cancary

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
// main.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  return EXIT_SUCCESS;
}

void canary_strong()
{
  typedef struct MyStruct {
    char buf[0x4];
  }MyStruct;

  MyStruct myStruct;
}

void canary()
{
  char buf[0x8];
}

编译参数:

前言

ret2libc 即控制函数的执行 libc 中的函数,通常是返回至某个函数的 plt 处或者函数的具体位置 (即函数对应的 got 表项的内容)

函数调用约定和函数传参

当使用 ida pro 逆向分析时,函数开头总有这么一段:

前言

ret2syscall 是 Pwn 进阶中的一个重要概念,它允许我们通过修改返回地址来直接调用系统调用,从而实现更复杂的攻击。本文将介绍 ret2syscall 的基本原理和应用。

C 语言中的 puts read write 等函数实际上是对系统调用的封装。通过 ret2syscall,我们可以直接调用这些系统调用,而不需要依赖 libc 函数。

手写 shellcode

这里给出最经典的 shellcode

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    xor    eax, eax        ; eax = 0
    push   eax             ; push 0 (null terminator)
    push   0x68732f2f      ; push "//sh"
    push   0x6e69622f      ; push "/bin"
    mov    ebx, esp        ; ebx = pointer to "/bin//sh"
    push   eax             ; push 0 (argv[1] = NULL)
    mov    edx, esp        ; edx = pointer to NULL
    push   ebx             ; push pointer to "/bin//sh"
    mov    ecx, esp        ; ecx = pointer to argv
    mov    al, 0xb         ; syscall number for execve
    int    0x80            ; trigger syscall

最经典的 Linux x86(32位)shellcode,它的作用是执行 /bin/sh(获得 shell)

前言

ret2shellcode 即是将程序的控制流劫持到我们构造的 shellcode 上。shellcode 是一段可以被执行的代码,通常用于执行系统命令或打开一个 shell。

想要执行 sehllcode, shellcode 所在的内存区域必须是可执行的。