Skip to content

Instantly share code, notes, and snippets.

@leonjza
Last active August 14, 2019 08:38
Show Gist options
  • Save leonjza/a138ba4d53fc5dd63f7fe12630e477f5 to your computer and use it in GitHub Desktop.
Save leonjza/a138ba4d53fc5dd63f7fe12630e477f5 to your computer and use it in GitHub Desktop.
objection Flex plugin
import os
import click
from objection.utils.plugin import Plugin
from objection.commands.filemanager import _path_exists_ios, _upload_ios
from objection.commands.device import _get_ios_environment
from objection.state.connection import state_connection
class FlexLoader(Plugin):
""" FlexLoader loads Flex """
def __init__(self, ns):
"""
Creates a new instance of the plugin
:param ns:
"""
implementation = {
'meta': 'Work with Flex',
'commands': {
'load': {
'meta': 'Load flex',
'exec': self.load_flex
}
}
}
super().__init__(__file__, ns, implementation)
self.inject()
self.flex_dylib = 'libFlex.arm64.dylib'
def load_flex(self, args: list):
"""
Loads flex.
:param args:
:return:
"""
agent = state_connection.get_api()
device_dylib_path = os.path.join(agent.env_ios_paths()['DocumentDirectory'], self.flex_dylib)
if not _path_exists_ios(device_dylib_path):
print('Flex not uploaded, uploading...')
if not self._upload_flex(device_dylib_path):
return
click.secho('Asking flex to load...', dim=True)
self.api.init_flex(self.flex_dylib)
click.secho('Flex should be up!', fg='green')
def _upload_flex(self, location: str) -> bool:
"""
Uploads Flex to the remote filesystem.
:return:
"""
local_flex = os.path.join(os.path.abspath(os.path.dirname(__file__)), self.flex_dylib)
if not os.path.exists(local_flex):
click.secho('{0} not available next to plugin file. Please build it!'.format(self.flex_dylib), fg='red')
return False
_upload_ios(local_flex, location)
return True
namespace = 'flex'
plugin = FlexLoader

objection Flex plugin

This plugin should sideload Flex[1], loaded as a plugin in objection[2]. Flex itself should be a shared library (with your target's architecture as either a thin/fat Mach-o).

The source code for a shared library called libFlex is included in this gist as .h and .m files. You need to copy the Classes/ directory from the official Flex project[1] into your project.

[1] https://github.com/Flipboard/FLEX
[2] https://github.com/sensepost/objection

rpc.exports = {
initFlex: function (dlib) {
const NSDocumentDirectory = 9;
const NSUserDomainMask = 1
const p = ObjC.classes.NSFileManager.defaultManager()
.URLsForDirectory_inDomains_(NSDocumentDirectory, NSUserDomainMask).lastObject().path();
ObjC.schedule(ObjC.mainQueue, function () {
const libFlexModule = Module.load(p + '/' + dlib);
const libFlexPtr = libFlexModule.findExportByName("OBJC_CLASS_$_libFlex");
const libFlex = new ObjC.Object(libFlexPtr);
libFlex.alloc().init().flexUp();
});
}
}
#import <Foundation/Foundation.h>
@interface libFlex : NSObject
- (id)init;
- (void)logSomething:(NSString *)something;
- (void)flexUp;
@end
#import "libFlex.h"
#import "FlexManager.h"
@implementation libFlex
- (id)init
{
self = [super init];
return self;
}
- (void)logSomething:(NSString *)something
{
NSLog(@"%@", something);
}
- (void)flexUp {
[[FLEXManager sharedManager] showExplorer];
}
@end
static void __attribute__((constructor)) initialize(void){
NSLog(@"==== Booted ====");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment