4

PIE

 2 years ago
source link: https://taardisaa.github.io/2022/03/10/PIE/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Tardis's blog

发表于

2022-03-10 更新于 2022-03-11 分类于 Other


本文字数: 1.8k 阅读时长 ≈ 2 分钟

pie会影响逆向分析。讨论一下解决方案。

ASLR 与 PIE 的同与异_SkYe’s Blog-CSDN博客_aslr和pie

[PIE保护详解和常用bypass手段 - 安全客,安全资讯平台 (anquanke.com)](https://www.anquanke.com/post/id/177520#:~:text=什么是PIE呢?. PIE全称是position-independent,executable,中文解释为地址无关可执行文件,该技术是一个针对代码段(.text)、数据段(.data)、未初始化全局变量段(.bss)等固定地址的一个防护技术,如果程序开启了PIE保护的话,在每次加载程序时都变换加载地址,从而不能通过ROPgadget等一些工具来帮助解题. 开启PIE保护的时候每次运行时加载地址是随机变化的.)

PIE全称是position-independent executable,中文解释为地址无关可执行文件,该技术是一个针对代码段(.text)、数据段(.data)、未初始化全局变量段(.bss)等固定地址的一个防护技术。

使用上次CGO逆向的my.go文件测试。

package main

/*
#include <stdio.h>
static void SayHello(const char* s) {
puts(s);
}
*/
import "C"

func main() {
C.SayHello(C.CString("Hello, World\n"))
}
go build -buildmode=pie -o my_pie.exe my.go

记一下默认main.main地址:0x46F9C0

跑起来后:0x1CF9C0

发生了变化。

逆向随机基址 全解决方案 - So who are you (kms.app)

PIE这个玩意确实很鸡贼。有的程序会依赖这个,所以直接关闭会出现意想不到的结果。不关闭的话,每次逆向都要重新找基址,很麻烦。

关闭PIE

Windows

这玩意的开启与关闭就存储在Nt header中。

找到DllCharacteristics设置,修改比特位进行关闭。

可以使用CFF Explorer进行修改,关闭Dll can move选项。

测试(持续记录)

  1. Go-PIE:关闭后无影响。

Linux

网上一堆关于开了PIE后如何bypass啥的,但是我是个逆向手,我当前不需要知道这个,我只想知道如何直接关闭。

https://reverseengineering.stackexchange.com/questions/22731/convert-pie-elf-binary-into-no-pie

set disable-randomization on

这样能强行默认加载代码段于一个基址保持不变。大概是 0x555555554000

堆栈段似乎由于由ASLR管控,所以没关闭的话,还是会随机化的。

https://sourceware.org/gdb/current/onlinedocs/gdb.pdf

真没想出来办法,似乎没给这个操作。

root权限

sudo -i

直接关ASLR,这样似乎能够同时把PIE给失效掉。

echo 0 > /proc/sys/kernel/randomize_va_space

这样IDA也能享受不变基址的操作了。

首先在IDA中获取静态情况下的入口地址static_addr

然后动态调试时记录入口地址的真正值real_addr。(在x64dbg上动态追踪,或者另开一个IDA动态跑)

得到了real_addr - static_addr相差偏移,那么就可以通过任一静态地址获得其具体的动态地址了。

IDA Rebase Program

Edit->Segments->Rebase program

修改Image base或者提供刚刚计算出来的Shift delta

IDA自适应不一定万能,出了啥映射错误的话还是不好处理

每调试一次都要修一遍。

能直接关PIE肯定直接关,轻轻松松的事情。

Disable ASLR and stop IDA rebasing | Will Donohoe

Linux下关闭ALSR(地址空间随机化)的方法_counsellor的专栏-CSDN博客_linux关闭地址随机化


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK