Containers.md
In this passage I’ll show the notes of Containers in CS_61A. Box-and-Pointer NotationThis is just an easy diagrams to show lists in Environment Diagrams like this Processing Container Values Several built-in functions take iterable arguments and aggregate them into a value. sum sum(iterable) -> value sum(iterable, start) -> value This expression return the sum of an iterable of numbers (Not strings) plus the value of parameter ‘start’ (which defaults to 0). When the iterable is...
ret2syscall.md
ret2text 只有在程序调用了危险函数并且能够使用栈溢出覆盖返回地址的情况下才能够使用,而 ret2shellcode 也需要程序没有开启 NX (No eXecutable) 的情况下才能使用。如果程序开启了 NX 防护,我们就需要考虑别的办法了。 这里介绍第一种: ret2syscall ret2syscall 概述 顾名思义,ret2syscall 就是返回到系统调用。所以利用 ret2syscall 的攻击就是构造一个 syscall 的 ROP 链,然后利用栈溢出劫持程序流程,转到 ROP 链执行,利用 ROP getshell。 使用前提 存在栈溢出漏洞,能够覆盖返回地址劫持程序运行流程 能够找到合适的 gadget 用于构造 ROP 链 能够执行系统调用 大概思路首先查看程序的栈溢出漏洞,利用gdb动态调试 + cyclic 分析出偏移量,填充缓冲区 接着使用 ROPgadget 查找 gadget,获取其地址 最后在payload中构造 ROP 链,完成系统调用。 先讲讲系统调用这是一个 Linux...
Fuxiang's Instruction
先安装arch-linux-xdg-menus 123$ sudo pacman -S archlinux-xdg-menu$ sudo ln /etc/xdg/menus/arch-applications.menu /etc/xdg/menus/applications.menu $ XDG_MENU_PREFIX=kbuildsycoca6 --noincremental # 好像没有用 这样大概就解决了在dolphin中无法选择使用什么应用打开的问题了,但是还有一个问题,那就是kitty默认终端的设置:参考网站:Arch wiki 1$ nvim ~/.config/kdeglobals 在~/.config/kdeglobals中添加如下行 text12[General]TerminalApplication=kitty
Compile
编译是将源代码变成可执行程序的过程,这个过程可以分为以下步骤: 预处理 编译 汇编 链接 下面以gcc为例解释每个阶段 预处理阶段 预处理阶段主要是处理源代码中以’#’开始的预处理指令,将其转换后直接插入程序文本中,得到另一个C源码,通常以”.i”作为文件扩展名。 例如此时有一个文件 hello.c: 12345#include <stdio.h>int main(void) { printf("hello world"); return 0;} 预处理命令: 1$ gcc -E hello.c -o hello.i 简单来说预处理阶段的一些处理规则如下: 递归处理 #include 命令,将对应文件的内容复制到该指令所在的位置 删除所有的 #define 命令,并替换为对应的宏 处理所有的条件预处理指令,比如” #if, #ifdef, #endif...
Linking
什么是链接呢?链接就是把多个目标文件、库文件组合成一个可执行文件(或共享库、静态库)的过程。链接分为两类: 静态链接:直接把库代码复制进可执行文件 动态链接:程序运行的时候加载共享库 链接时主要解决的问题: 符号解析 (Symbol Resolution) 地址和段重定位 (Relocation)
config the IA-32 utils for arch
在 Arch Linux 上运行和调试 32 位程序需要安装 32 位兼容库和必要的工具链。由于 Arch Linux 默认不启用 multilib (32位兼容支持), 你需要手动配置。 启用 multilib 仓库 修改 /etc/pacman.conf 1$ sudo vim /etc/pacman.conf 找到下面这一行,并取消注释 12[multilib]Include = /etc/pacman.d/mirrorlist 然后再更新软件包数据库: 1$ sudo pacman -Sy 安装32位运行环境 安装32位基础库 1$ sudo pacman -S lib32-glibc lib32-gcc-libs 安装32位调试工具 1$ sudo pacman -S gdb-multilib
Sequence
I’m learning the CS_61A course since January 2024, but there was a long time I suspended the learning of this course to learn some other subjects like Algorithm and Data Structure, and pwn in CTF. And now it’s time to continue the learning. Sequences are a list of Data in a specific order such as queues, arrays and linked lists. ListWe should know that Python does not have a built-in array type (like C arrays) that’s available without importing a module. But there is a list type in...
What_is_ELF
I always see ELF in some passages. And now it’s time to deeply see what it is. ELF actually is Executable and Linkable Format. Yes, it’s a format for file (specifically for binary file such as Executable Program, Object Code and Shared Library Files) ELF 文件的类型 可重定位文件 (Relocatable File): 由源文件编译而成尚未链接的目标文件,通常以 .o 作为扩展名。用于与其它目标文件进行链接以构成可执行文件或动态链接库。 可执行文件 (Executable File): 经过链接的、可执行的目标文件,就是我们通常在 Linux 中执行的程序。 共享目标文件 (Shared Object File),...
ret2shellcode.md
After learning ret2text, here comes the ret2shellcode.ret2text的前提是程序中包含了系统调用shell的代码,只要直接覆盖返回地址到敏感代码就可以直接getshell了,但是实际上基本没有什么程序会包含这样的敏感代码,而这时候就需要自己去构造敏感代码了。 前提 程序中存在栈溢出漏洞,没有开启canary保护,并且溢出大小合适,能够让我们注入shellcode并覆盖返回地址。 由于我们要向程序中注入shellcode并且执行,所以要求程序中包含可读可写可执行的片段,比如没有开启NX (No eXecutable)保护的栈帧片段。 Implementation (只介绍在栈帧中注入shellcode的情况)准备shellcode最简单的shellcode就是execve('/bin/sh', NULL,...
ret2text.md
参考网站:CTF Wiki ret2text 是最简单的利用栈溢出漏洞来getshell的方法,这种方法就是利用程序中已经有的敏感命令比如system('/bin/sh')来getshell 前提 程序存在栈溢出,并且溢出大小合适,能够覆盖函数返回地址。 程序中存在敏感命令的调用,我们能够获取其地址。 程序没有开启canary保护,栈溢出可以被利用。 Implementation 找到敏感命令system('/bin/sh')的地址 计算esp到返回地址的偏移量,构造payload覆盖返回地址为敏感命令的地址 运行程序,getshell Template1234567from pwn import *context.binary = elf = ELF('./vuln')context.log_level = 'debug'p = remote('ip', port)payload = <padding> + <loc of vulnerable...