[转]Patching the Mach-o Format the Simple and Easy Way
From:http://secureallthethings.blogspot.jp/2014/08/patching-mach-o-format-simple-and-easy.html
I'm relatively new to mac research. So when I find something new, that seems cutting edge, but relatively simple I question it. Has anyone else done this before? Is this in the public domain? Is this in the academic domain that I have no way of researching?
I google like hell.
I question myself (for a short period of time).
I write my congressman.
I wait.
I try to contact people in the know without letting them know to much.
Then I'm afraid I've said too much.
So here we are.
Thank's to the guys in #osxre (fg!) for telling what would work and not work.
This is my 'new' method for patching the mach-o format.
The macho format is simply nested segments in a very straight forward waterfall format that IMHO is much more simple than the PE and ELF formats.
As you have seen many times, this is the format, no seriously, this is it:

What is so special about this format?
It is very hackable easy to modify, far easier than ELF and PE formats.
There are not many code caves in a mach-o executable:
$ file ls.mach-o
ls.mach-o: Mach-O 64-bit executable x86_64
$ python ./find_caves.py ls.mach-o
[*] Looking in ls.mach-o for caves
[*] Looking for caves of 50 byes in size
No section
->Begin Cave 0x736
->End of Cave 0x10f8 # <--- Remember this one
Size of Cave (int) 2498
**************************************************
No section
->Begin Cave 0x4ff6
->End of Cave 0x5038
Size of Cave (int) 66
**************************************************
No section
->Begin Cave 0x54d1
->End of Cave 0x6000
Size of Cave (int) 2863
**************************************************
[*] Total of 3 caves found
The caves are large, but they are not in a section that includes read/execute attributes.
But let's look at the beginning of the __TEXT/_text segment/section:

Let's look at lower address space, what's going on?

Continuing:

Continuing:

You get the idea. Many zeros. Much waste. Wow.
But that looks like enough room for shellcode, right? (The answer is yes).
How do we make that part of the __TEXT,__text segment/section?
Easy:
1. Change the __text section Address and Offset to the beginning of your shellcode and Size to accommodate your new shellcode.
Before:

After:

2. Change LC_Main to point to the __text Offset or if a LC_UNIXTHREAD binary make sure [eip|rip] points to the new __text Address.
Before:

After:
3. You need to fork() your shellcode so that it continues after the parent has completed and you need to make sure that what LC_MAIN/LC_UNIXTHREAD was pointing to originally is the first thing that is executed whether a dyld or the __text section. Here I have the shellcode that I use in my POC.

And that's it. No really. That's it.
Here's the beginning of the __TEXT Segment after:

As you may have already figured out, this method works on both LC_MAIN and LC_UNIXTHREAD binaries. Also, this will work from within Fat binaries.
Proof:
![]() |
| Top window: netcat listener Bottom window: Executing the patched ls.macho showing all the other successfully patched bins with my POC. |
I've already automated the i386/x64 intel chipset mach-o patching, expect an update in BDF supporting these chipsets and Fat binaries containing these mach-o formats.
Cheers,
Midnite_runr
[转]Patching the Mach-o Format the Simple and Easy Way的更多相关文章
- SNMP: Simple? Network Management Protocol(转)
转自:http://www.rane.com/note161.html An SNMP Overview The Message Format The Actual Bytes Introductio ...
- Remote Desktop File Format
转自:http://engrmosaic.uncc.edu/mosaic-anywhere/remote-desktop-file-format The new Terminal Services c ...
- Awesome Python
Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. Insp ...
- Machine and Deep Learning with Python
Machine and Deep Learning with Python Education Tutorials and courses Supervised learning superstiti ...
- Python开源框架、库、软件和资源大集合
A curated list of awesome Python frameworks, libraries, software and resources. Inspired by awesome- ...
- Python 库汇总英文版
Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. Insp ...
- (转) [it-ebooks]电子书列表
[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...
- Java资源大全中文版(Awesome最新版)
Awesome系列的Java资源整理.awesome-java 就是akullpp发起维护的Java资源列表,内容包括:构建工具.数据库.框架.模板.安全.代码分析.日志.第三方库.书籍.Java 站 ...
- JavaScript资源大全中文版(Awesome最新版)
Awesome系列的JavaScript资源整理.awesome-javascript是sorrycc发起维护的 JS 资源列表,内容包括:包管理器.加载器.测试框架.运行器.QA.MVC框架和库.模 ...
随机推荐
- 使用C#实现顺序队列
队列(Queue)是插入操作限定在表的尾部而其它操作限定在表的头部进行的线性表.把进行插入操作的表尾称为队尾(Rear),把进行其它操作的头部称为队头(Front).当对列中没有数据元素时称为空对列( ...
- javascript、jQuery的扩展方法,扩展实例展示代码
$(function () { var total = 0, height = $(window).height(), memberScroll, cartScroll, proScroll; ...
- measureChildren作品
无论是在改写View依然是ViewGroup什么时候.特别ViewGrop什么时候,通常是不可避免的重写onMeasure方法,我们一定会调用setMeasuredDimension()将測量好的宽高 ...
- hdu1047 Integer Inquiry 多次大数相加
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047 Problem ...
- 关于重写ID3 Algorithm Based On MapReduceV1/C++/Streaming的一些心得体会
心血来潮,同时想用C++连连手.面对如火如荼的MP,一阵念头闪过,如果把一些ML领域的玩意整合到MP里面是不是很有意思 确实很有意思,可惜mahout来高深,我也看不懂.干脆自动动手丰衣足食,加上自己 ...
- 登录记住账号和密码小Demo
读取 // 1.读取沙盒中plist文件 // 1.1.获得沙盒根路径 NSString *home = NSHomeDirectory(); // 1.2.拼接Documents路径 NSStrin ...
- java设计模式之八代理模式(Proxy)
其实每个模式名称就表明了该模式的作用,代理模式就是多一个代理类出来,替原对象进行一些操作,比如我们在租房子的时候回去找中介,为什么呢?因为你对该地区房屋的信息掌握的不够全面,希望找一个更熟悉的人去帮你 ...
- aspnet-webapi-2-contrib
https://github.com/rdingwall/protobuf-net-data https://github.com/mgravell/protobuf-net https://gith ...
- thrift实现js与C#通讯
利用thrift实现js与C#通讯的实例代码 1.为什么要用thrift js C#? 1.1 首先,js 通过 thrift 访问C#,实际上是一种c/s模式.thrift是通信工具,js是客户端, ...
- 萧墙HTML5手机发展之路(53)——jQueryMobile页面之间的参数传递
基于单个页面模板HTTP通过路POST和GET请求传递参数.在多页模板,并且不需要server沟通,通常有三种方式在多页模板来实现页面之间的参数传递. 1.GET道路:上一页页生成参数并传递到下一个页 ...
