Giter Site home page Giter Site logo

bfinject's Introduction

bfinject

Easy dylib injection for jailbroken 64-bit iOS 11.0 - 11.1.2. Compatible with Electra and LiberiOS jailbreaks.

bfinject loads arbitrary dylibs into running App Store apps. It has built-in support for decrypting App Store apps, and comes bundled with iSpy and Cycript.

bfinject is a wrapper that takes care of correctly codesigning your dylibs before injecting them using bfinject4realz. It's completely standalone, doesn't require jailbreakd, QiLin, or anything like that. It just works.

Note: bfinject does not work on Electra if "Tweaks" is enabled. Reboot and re-run Electra without tweaks in order to use bfinject. If you see errors with "thread_create", this is the problem.

Note: bfdecrypt is available as a standalone dylib here: https://github.com/BishopFox/bfdecrypt/

Navigate

Electra Setup

  • Jailbreak your iOS 11.0 - 11.1.2 device with Electra >= b7
  • Copy the bfinject tarball, https://github.com/BishopFox/bfinject/raw/master/bfinject.tar, onto your jailbroken device. You might need to copy it to your laptop first because Github enforces SSL, but the Electra version of wget doesn't support SSL.
ssh root@your-device-ip # (the password is 'alpine')
mkdir bfinject
cd bfinject
wget http://<your_server>/bfinject.tar
tar xvf bfinject.tar

LiberiOS Setup

  • Jailbreak your iOS 11.0 - 11.1.2 device with LiberiOS >= 11.0.3
  • Copy the bfinject tarball, https://github.com/BishopFox/bfinject/raw/master/bfinject.tar, onto your jailbroken device. You might need to copy it to your laptop first because Github enforces SSL, but the LiberiOS version of wget doesn't support SSL.
ssh root@your-device-ip # (the password is 'alpine')
export PATH=$PATH:/jb/usr/bin:/jb/bin:/jb/sbin:/jb/usr/sbin:/jb/usr/local/bin:
cd /jb
mkdir bfinject
cd bfinject
wget http://<your_server>/bfinject.tar
tar xvf bfinject.tar

Using bfinject

  • Launch the target app into which you will inject your shared library
  • Type bash bfinject for help
  • NOTE: it's important to precede the command with bash or it won't work. Sandbox yadda yadda.
-bash-3.2# bash bfinject
Syntax: bfinject [-p PID | -P appname] [-l /path/to/yourdylib | -L feature]

For example:
   bfinject -P Reddit.app -l /path/to/evil.dylib   # Injects evil.dylib into the Reddit app
     or
   bfinject -p 1234 -L cycript                     # Inject Cycript into PID
     or
   bfinject -p 4566 -l /path/to/evil.dylib         # Injects the .dylib of your choice into PID

Instead of specifying the PID with -p, bfinject can search for the correct PID based on the app name.
Just enter "-P identifier" where "identifier" is a string unique to your app, e.g. "fing.app".

Available features:
  cycript    - Inject and run Cycript
  decrypt    - Create a decrypted copy of the target app
  test       - Inject a simple .dylib to make an entry in the console log
  ispy       - Inject iSpy. Browse to http://<DEVICE_IP>:31337/

A Simple Test

Before doing anything more complex, test that it works. bfinject has built-in self tests. Here's an example using the Reddit app as the target:

Cs-iPhone:~ root# bash bfinject -P Reddit -L test
[+] Electra detected.
[+] Injecting into '/var/containers/Bundle/Application/55C94FAA-A282-4FDC-967D-6A012D01087E/Reddit.app/Reddit'
[+] Getting Team ID from target application...
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID 2TDUX39LX8 and platform entitlements...
[bfinject4realz] Calling task_for_pid() for PID 486.
[bfinject4realz] Calling thread_create() on PID 486
[bfinject4realz] Looking for ROP gadget... found at 0x1019a2ba0
[bfinject4realz] Fake stack frame at 0x12ac5c000
[bfinject4realz] Calling _pthread_set_self() at 0x182bfb814...
[bfinject4realz] Returned from '_pthread_set_self'
[bfinject4realz] Calling dlopen() at 0x1829bb460...
[bfinject4realz] Returned from 'dlopen'
[bfinject4realz] Success! Library was loaded at 0x1c016e1c0
[+] So long and thanks for all the fish.

On the device screen you should see this:

If not, something is broken ;)

Decrypt App Store apps

Here's an example decrypting the Reddit app on an Electra-jailbroken iPhone:

Cs-iPhone:~ root# bash bfinject -P Reddit -L decrypt
[+] Electra detected.
[+] Injecting into '/var/containers/Bundle/Application/BCEBDD64-6738-45CE-9B3C-C6F933EA0793/Reddit.app/Reddit'
[+] Getting Team ID from target application...
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID 2TDUX39LX8 and platform entitlements...
[bfinject4realz] Calling task_for_pid() for PID 3218.
[bfinject4realz] Calling thread_create() on PID 3218
[bfinject4realz] Looking for ROP gadget... found at 0x1016a5110
[bfinject4realz] Fake stack frame at 0x10a06c000
[bfinject4realz] Calling _pthread_set_self() at 0x181303814...
[bfinject4realz] Returned from '_pthread_set_self'
[bfinject4realz] Calling dlopen() at 0x1810c3460...
[bfinject4realz] Returned from 'dlopen'
[bfinject4realz] Success! Library was loaded at 0x1c03e1100
[+] So long and thanks for all the fish.

You'll see this screen on your device:

Once it's complete, you'll be presented with a UI alert to ask if you want to spawn a service from which you can download your decrypted IPA:

If you tap Yes, a service will be spawned on port 31336 of your device. Connect to it and you'll be sent a raw copy of the IPA that can be downloaded with netcat like so:

carl@calisto-3 /tmp $ nc 192.168.1.33 31336 > decrypted.ipa
carl@calisto-3 /tmp $ ls -l decrypted.ipa
-rw-r--r--  1 carl  wheel  14649063 Jan 25 16:57 decrypted.ipa
carl@calisto-3 /tmp $ file decrypted.ipa
decrypted.ipa: iOS App Zip archive data, at least v2.0 to extract

Alternatively, check the console log for the device, it will tell you where the decrypted IPA is stored. For example:

[dumpdecrypted] Wrote /var/mobile/Containers/Data/Application/6E6A5887-8B58-4FC5-A2F3-7870EDB5E8D1/Documents/decrypted-app.ipa

You can also search the filesystem for the IPA like so:

find /var/mobile/Containers/Data/Application/ -name decrypted-app.ipa

Getting the .ipa off the device can be done with netcat. On your laptop, set up a listener service:

ncat -l 0.0.0.0 12345 > decrypted.ipa

And on the jailbroken device:

cat /path/to/decrypted.ipa > /dev/tcp/<IP_OF_YOUR_COMPUTER>/12345

The .ipa will be a clone of the original .ipa from the App Store, except that the main binary and all its accompanying frameworks and shared libraries will be decrypted. The CRYPTID flag will be 0 in each previously-encrypted file. You can take the .ipa, extract the app, modify it as needed, re-sign it with your own developer cert, and deploy it onto non-jailbroken devices as needed.

Cycript

One of bfinject's features is to incorporate common pentesting tools, like Cycript. More will be added with time. To use Cycript you will need the Cycript command-line client installed on your MacBook (http://www.cycript.org/). Then, once bfinject is installed on your test device, do something like this example in which we inject Cycript into the Reddit app:

Cs-iPhone:~ root# bash bfinject -P Reddit -L cycript
[+] Electra detected.
[+] Injecting into '/var/containers/Bundle/Application/55C94FAA-A282-4FDC-967D-6A012D01087E/Reddit.app/Reddit'
[+] Getting Team ID from target application...
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID 2TDUX39LX8 and platform entitlements...
[bfinject4realz] Calling task_for_pid() for PID 486.
[bfinject4realz] Calling thread_create() on PID 486
[bfinject4realz] Looking for ROP gadget... found at 0x1019a2ba0
[bfinject4realz] Fake stack frame at 0x10ab00000
[bfinject4realz] Calling _pthread_set_self() at 0x182bfb814...
[bfinject4realz] Returned from '_pthread_set_self'
[bfinject4realz] Calling dlopen() at 0x1829bb460...
[bfinject4realz] Returned from 'dlopen'
[bfinject4realz] Success! Library was loaded at 0x1c01786c0
[+] Injecting into '/var/containers/Bundle/Application/55C94FAA-A282-4FDC-967D-6A012D01087E/Reddit.app/Reddit'
[+] Getting Team ID from target application...
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID 2TDUX39LX8 and platform entitlements...
[bfinject4realz] Calling task_for_pid() for PID 486.
[bfinject4realz] Calling thread_create() on PID 486
[bfinject4realz] Looking for ROP gadget... found at 0x1019a2ba0
[bfinject4realz] Fake stack frame at 0x10ab00000
[bfinject4realz] Calling _pthread_set_self() at 0x182bfb814...
[bfinject4realz] Returned from '_pthread_set_self'
[bfinject4realz] Calling dlopen() at 0x1829bb460...
[bfinject4realz] Returned from 'dlopen'
[bfinject4realz] Success! Library was loaded at 0x1c4179680
[+] So long and thanks for all the fish.

Once Cycript has been injected, you'll see the following message on your device:

You can connect to Cycript from your MacBook like this (assuming you installed Cycript into ~/bin/):

carl@calisto-3 /tmp $ ~/bin/cycript -r 192.168.1.33:1337
cy# UIApp
#"<RedditApplication: 0x102304a30>"
cy#

How does it work?

At a high level, bfinject4realz side-loads a self-signed .dylib into a running Apple-signed App Store app.

The process is done in two stages.

1. Sign the dylib to be injected

Codesigning checks on iOS comprise userspace services (amfid) and kernel services (AppleMobileFileIntegrity). Both LiberiOS and Electra patch the userspace amfid process to bypass codesigning checks, but there are still further checks performed by the kernel.

However, Electra and LiberiOS are KPPless, which means they don't patch anything in the kernel; not a single byte. This is because of Kernel Patch Protection ("KPP"), an Apple security technology that does sophisticated kernel introspection to detect and thwart kernel patches. As a result, kernel codesigning checks are still intact.

Fortunately for us, it appears that the kernel assumes amfid has already checked the validity of the cryptographic signature attached to a dylib's entitlements. As a result, all we need to do is self-sign two entitlements into a dylib if we want the kernel to accept it:

  • The first is the platform-application entitlement, which I believe indicates that the dylib is Apple software.
  • The second is the Team ID of the signing certificate that was used to sign the code we are injecting into. For example, the Reddit app is signed by Team ID 2TDUX39LX8. As a result, to inject a dylib into the Reddit app we must sign the dylib with the same Team ID: 2TDUX39LX8.

bfinject takes care of all the signing shenanigans for you, which is nice.

2. Inject the correctly-signed dylib into the target process

  • Using task_for_pid(), get a mach port for the target process
  • Use the port to manipulate threads and non-executable memory segments in the target process
    • Note: without kernel patches, it is not possible to modify executable code in a process.
    • As a result, we have to use ROP tricks to execute code of our choice.
  • Allocate some memory pages in the remote process for a new temporary stack
  • Place the string "/path/to/my.dylib" at known location in stack
  • Use some tricks to lookup the address of dlopen() in the remote process
  • Find a simple RET ROP gadget in an executable page (RET = "\xc0\x03\x5f\xd6" on arm64)
  • Create a new thread in the target process
  • Set CPU registers for the thread:
    • $pc = Address of dlopen()
    • $x0 = Parameter 1 of dlopen: address of string "/path/to/dylib" in temporary stack
    • $x1 = Parameter 2 of dlopen: the value RTLD_LAZY | RTLD_GLOBAL
    • $sp = Middle of the temporary stack
    • $fp = Quarter way into the temporary stack
    • $lr = Address of ROP gadget
  • Resume the thread. The following will happen:
    • _pthread_set_self is called in order to setup threading for dlopen()
    • dlopen() is called to inject our evil shared library
    • dlopen() will RET to the value in the $lr register, which is another RET instruction
    • RET will return to RET will return to RET... ad infinitum
  • Poll the thread's registers to check for $pc == address of ROP gadget (the RET instruction)
  • Once the gadget is hit, terminate the thread, free the memory, job done.

For a low-level description, see the source.

Known issues

Note that on Electra, the version of jtool (@morpheus' code-signing multitool) doesn't support platform binary entitlements, so bfinject supplies jtool from LiberiOS and uses that instead. bfinject does not use Electra's inject_criticald.

Credits

bfinject's People

Contributors

0xhaggis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bfinject's Issues

WC: Command not found

When i executed bash bfinject -P Reddit -L test, i received this error:

bfinject: line 43: wc: command not found
[!] "Reddit" was not uniquely found, please check your criteria.

Where do i take the wc command from? I tried searching in Cydia but it's not in the default sources.

[Electra 1.0.1] - iOS 11.1.2

Thanks!

"cannot execute binary file"

iPhone 7
iOS 12.1.2
Chimera jailbreak 1.0.2

iPhone:~ root# bash bfinject4realz -p 571 -L cycript
bfinject4realz: bfinject4realz: cannot execute binary file

error can't allocate region

i get this error when I try and crack an IPA from the iTunes store Instead of app store. (iTunes store is on pc)

No TEAM ID

Can someone help me how can i get The target app TEAM ID ? Iam new in bfinject :(
And when i try to run the bash bfinject -P 714 -L test it said no Team id

'jtool /electra/usr/local/bin/ signing error. barfing'

I recently installed Electra and installed bfinject and am getting this error when I try to run anything:

iPhone:~/bfinject root# bash bfinject -p 402 -L test
[+] Electra detected.
bfinject: line 172: md5sum: command not found
bfinject: line 173: md5sum: command not found
cp: '/electra/usr/local/bin/bfinject4realz' and '/electra/usr/local/bin/bfinject4realz' are the same file
bfinject: line 184: tail: command not found
bfinject: line 184: cut: command not found
[+] Injecting into ''
[+] Getting Team ID from target application...
bfinject: line 199: tail: command not found
bfinject: line 199: cut: command not found
bfinject: line 199: cut: command not found
[+] WARNING: No Team ID found. Continuing regardless, but expect weird stuff to happen.
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID  and platform entitlements...
jtool /electra/usr/local/bin/ signing error. barfing.

I also tried running the command with -P instead of the PID and when I do that I get:
'[!] "Appname" was not uniquely found, please check your criteria'

I'm not sure what's going on, the only thing I can think of that was odd was when I installed Electra and went to my general settings, there was no 'devices and profile management' section where I had to click 'trust' to launch Electra -- and Electra launched fine and jailbroke. I think that this may just be because I have a full apple developer account however.

Also, I did install Electra with tweaks disabled

Thanks!

bfinject stuck at signing injectable .dylib with Team ID XXXXX and platform entitlements

Running bfinject on iOS 11.2.2 with Electra 1.3.2 and it stuck at at the following phase.

iphone:/usr/local/tools/bfinject root# ./bfinject -p 4699 -L decrypt
[+] Electra detected.
[+] Injecting into '/var/containers/Bundle/Application/5E39DFBF-881B-459D-9DCB-64DAA52196B6/Recolor.app/Recolor'
[+] Getting Team ID from target application...
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID TW66A342VK and platform entitlements...

When I manually run "bfinject4realz 4699 bfdecrypt.dylib", I get the following error.

[bfinject4realz] Returned from 'dlerror' 3262e1c3(682,0x1b27b4b80) malloc: *** mach_vm_map(size=6092734464) failed (error code=3)

Any idea on this? Any more info that is required?

bfinject: line 182 command not found

Hi, I'm trying this on Electra b7 and get the error (regardless what app):

/bootstrap/bfinject root# bash bfinject -p 481 -L decrypt [+] Electra detected. [+] Injecting into '/var/containers/Bundle/Application/4F70322B-9079-4490-81EA-40C4AAF12CD5/Reddit.app/Reddit' [+] Getting Team ID from target application... [+] Signing injectable .dylib with Team ID 2TDUX39LX8 and platform entitlements... bfinject: line 182: 0a89bbca313be61ff6194fab53cd0e30: command not found [+] So long and thanks for all the fish.

There might be as well a bug with binaries, which have spaces like 1-2-3 Tanken or DB Navigator.
Thanks for the great work.

Cycript section of the guide. Windows please?

I'm reading the guide and at the end of the cycript section there's this text: "You can connect to Cycript from your MacBook like this (assuming you installed Cycript into ~/bin/)"

I don't happen to have a Mac and I really want to run Cycript with my iPad. Is there any equivalent step for Windows?

MD5 command not found

I'm running Electra 11-3 on an iPhone 5S with iOS 11.0.3.

I did a fresh Electra install with No Tweaks and followed the Electra instructions with the most recent version of bfinject. I'm seeing these errors when running:

bash bfinject -P Reddit -L test

[+] Electra detected.
bfinject: line 163: md5: command not found
bfinject: line 164: md5: command not found
cp: '/bootstrap/usr/local/bin/bfinject4realz' and '/bootstrap/usr/local/bin/bfinject4realz' are the same file
[+] Injecting into '/var/containers/Bundle/Application/F0ABA1CC-E72A-4D88-AF1C-95D855B3BA83/Reddit.app/Reddit'
[+] Getting Team ID from target application...
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID 2TDUX39LX8 and platform entitlements...
jtool /bootstrap/usr/local/bin/ signing error. barfing.
Coles-iPhone:~/bfinject root# 

Any ideas? Thanks!

appex not decrypt ?

sh bfinject -p APP_PROCESS_NUM -L decrypt
ipa created successfully, but the Plugin/xxx.appex/xxx is not decrypted.

I've tried the appex executable's process number:

[+] Electra detected.
[+] Injecting into '/private/var/containers/Bundle/Application/46E55B2F-C46C-496A-90F1-007456442C35/DemoApp.app/PlugIns/DemoAppEx.appex/DemoAppEx'
[+] Getting Team ID from target application...
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID JAU66K5B9X and platform entitlements...
[bfinject4realz] Calling task_for_pid() for PID 396.
[bfinject4realz] Calling thread_create() on PID 396
[bfinject4realz] Looking for ROP gadget... found at 0x180ca7118
[bfinject4realz] Fake stack frame at 0x102aa4000
[bfinject4realz] Calling _pthread_set_self() at 0x180f7471c...
[bfinject4realz] Returned from '_pthread_set_self'
[bfinject4realz] Calling dlopen() at 0x180ca6e7c...
[bfinject4realz] Returned from 'dlopen'
[bfinject4realz] Success! Library was loaded at 0x12fe503b0
[+] So long and thanks for all the fish.

It seems like -L decrypt does NOT support appex at all ?

Can't inject into WhatsApp.app

Unfortunately I can't inject into WhatsApp.app... bfinject returns success, but not even the simple dylib injection creates the success popup on the iPhone

root@iPhone (/jb/bfinject) #bash bfinject -P WhatsApp.app -L iSpy
[+] Liberios detected
[+] Injecting into '/var/containers/Bundle/Application/22991067-E622-4525-BC16-12287B29005D/WhatsApp.app/WhatsApp'
[+] Getting Team ID from target application...
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID 57T9237FN3 and platform entitlements...
[bfinject4realz] Calling task_for_pid() for PID 835.
[bfinject4realz] Calling thread_create() on PID 835
[bfinject4realz] Looking for ROP gadget... found at 0x102fc6c08
[bfinject4realz] Fake stack frame at 0x12a800000
[bfinject4realz] Calling _pthread_set_self() at 0x186bff804...
[bfinject4realz] Returned from '_pthread_set_self'
[bfinject4realz] Calling dlopen() at 0x1869bf460...
[bfinject4realz] Returned from 'dlopen'
[bfinject4realz] Success! Library was loaded at 0x1c01f0e00
[+] So long and thanks for all the fish.

Decrypt without launching app

Issue

bfinject needs the app to be launched successfully, because it searches process name using ps.
Some applications I want to decrypt doesn't launch in jailbroken environment, so I need to decrypt them without launching it (or before launching process finishes).

Suggestion

Is it impossible to decrypt AppStore apps without launching it? The decrypting program called Clutch could do it (even though it doesn't seem to support iOS11).

Example

I could not test/decrypt/cycript com.aniplex.kirarafantasia app on AppStore [Link].
It has a jailbreak detection function when launching, and it kills itself quickly and bfinject cannot detect the app.
Please refer to the following log:

root# bash bfinject -P com.aniplex.kirarafantasia -L test
[!] "com.aniplex.kirarafantasia" was not uniquely found, please check your criteria.

[!] "xxx.app" was not uniquely found, please check your criteria.

This happens when I use either the PID, the executable name or the .app name.

Here's some examples:
bash bfinject -P flipbounce.app -L test
bash bfinject -P flipbounce -L test

Here's an example of when I use the PID:
bash bfinject -p flipbounce.app -L test

Output:
[+] Electra detected.
cp: '/bootstrap/usr/local/bin/bfinject4realz' and '/bootstrap/usr/local/bin/bfinject4realz' are the same file
[+] Injecting into ''
[+] Getting Team ID from target application...
[+] WARNING: No Team ID found. Continuing regardless, but expect weird stuff to happen.
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID and platform entitlements...
jtool /bootstrap/usr/local/bin/ signing error. barfing.

Research
After reviewing the script, it seems like there's a problem with grep. Here's an example:
ps -ax | grep flipbounce

Output
Killed

IPA file cannot be zipped

Hello,

I used BFinject to decrypt the twitter app as a test. I then transferred the decrypted ipa to my laptop using the tutorial provided. I tried to make the extension a .zip to unzip it but then it turns into a .cpgz. So i tried to run "class-dump -H twitter.ipa" and I get the error: class-dump: Input file (twitter.ipa) is neither a Mach-O file nor a fat archive. I tried this with other apps and the same things happen. Im just trying to load the ipa into ida-pro.

Anything will help, thanks.

ERROR: dlopen() failed to load the dylib.returned 0x0 (FAILURE)

First off, thanks for making bfinject. It's been a great learning tool for me. 😄

I'm on an iPhone 6 11.1.2 LiberiOS 11.0.3

When I try to decrypt or test the YouTube app. dlopen will fail to load the dylib. I've seen this a few times in other apps as well.

Any suggestions on what I can do?

root# bash bfinject -P YouTube -L decrypt
[+] Liberios detected
[+] Injecting into '/var/containers/Bundle/Application/B840EDE7-9E66-417C-8E4E-5B6BFFD7F394/YouTube.app/YouTube'
[+] Getting Team ID from target application...
[+] WARNING: No Team ID found. Continuing regardless, but expect weird stuff to happen.
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID  and platform entitlements...
[bfinject4realz] Calling task_for_pid() for PID 359.
[bfinject4realz] Calling thread_create() on PID 359
[bfinject4realz] Looking for ROP gadget... found at 0x1831c34e0
[bfinject4realz] Fake stack frame at 0x11f800000
[bfinject4realz] Calling _pthread_set_self() at 0x183403804...
[bfinject4realz] Returned from '_pthread_set_self'
[bfinject4realz] Calling dlopen() at 0x1831c3460...
[bfinject4realz] Returned from 'dlopen'
[bfinject4realz] ERROR: dlopen() failed to load the dylib.returned 0x0 (FAILURE)
[bfinject4realz] Calling dlerror() at 0x1831c32b0...
[bfinject4realz] Returned from 'dlerror'
41441718d5f6d4b7f3a15032f28e1728(1152,0x1b4384b80) malloc: *** mach_vm_map(size=6151880704) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
[bfinject4realz] dlerror() returned: (null)
[+] So long and thanks for all the fish.

ERROR: dlopen() failed to load the dylib.returned 0x0 (FAILURE)

IPad:~/bfinject-master root# ba
sh bfinject -P pushTanApp -L test
[+] Electra detected.
[+] Injecting into '/var/containers/Bund
le/Application/8410D1BF-BA8E-4459-84A7-0
D9AF603B098/pushTanApp.app/pushTanApp'
[+] Getting Team ID from target applicat
ion...
[+] Thinning dylib into non-fat arm64 im
age
[+] Signing injectable .dylib with Team
ID 9VCS76GRPT and platform entitlements.
..
[bfinject4realz] Calling task_for_pid()
for PID 1973.
[bfinject4realz] Calling thread_create()
on PID 1973
[bfinject4realz] Looking for ROP gadget.
.. found at 0x18303b118
[bfinject4realz] Fake stack frame at 0x1
055a8000
[bfinject4realz] Calling _pthread_set_se
lf() at 0x18330871c...
[bfinject4realz] Returned from '_pthread
_set_self'
[bfinject4realz] Calling dlopen() at 0x1
8303ae7c...
[bfinject4realz] Returned from 'dlopen'
[bfinject4realz] ERROR: dlopen() failed
to load the dylib.returned 0x0 (FAILURE)
[bfinject4realz] Calling dlerror() at 0x
18303accc...
[bfinject4realz] Returned from 'dlerror'
b23e11113793c2005cb0ea5861c9437c -(2097
,0x1b56aab40) malloc: *** mach_vm_map(si
ze=6099107840) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_bre
ak to debug
[bfinject4realz] dlerror() returned: (nu
ll)
[+] So long and thanks for all the fish.

TEAM ID is not found

I am testing a beta version of an application that was not installed from the App Store. When trying to use bfinject, a team ID is not found. I tried to debug by echoing the TEAMID variable when executing bfinject, but there are no results from JTOOL. It does not appear there are any entitlements for the application.

This is the following error I obtain:

screen shot 2018-07-09 at 1 50 29 pm

Applications crashing upon injection - BUG IN LIBDISPATCH: Unexpected error from mach_msg_receive

I'm trying to inject my library into a few applications (both AppStore & Enterprise Distribution signed) on iPhone8 (11.3), but the applications crash. The same dylib injects and works fine on other devices (only tried with 11.4b3).

iPhone:/User/Downloads/bfinject root# /bin/bash -c '/User/Downloads/bfinject/bfinject -p `ps -e | grep "[M]yAppName$" | while read -a array; do echo "${array[0]}" ; done` -l /User/Downloads/MyLib.dylib'
[+] Electra detected.
[+] Injecting into '/var/containers/Bundle/Application/12345678-90AB-CDEF-1234-567890ABCD/MyAppName.app/MyAppName'
[+] Getting Team ID from target application...
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID XXXXXXXXXX and platform entitlements...
[bfinject4realz] Calling task_for_pid() for PID 3503.
[bfinject4realz] Calling thread_create() on PID 3503
[bfinject4realz] Looking for ROP gadget... found at 0x18260b118
[bfinject4realz] Fake stack frame at 0x10e1e8000
[bfinject4realz] Calling _pthread_set_self() at 0x1828d871c...
[bfinject4realz] Returned from '_pthread_set_self'
[bfinject4realz] Calling dlopen() at 0x18260ae7c...

here, bfinject hangs, and the app crashes.

Attached is the crashed thread stack trace and relevant info from the crash report:

...
Hardware Model: iPhone10,1
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]

OS Version: iPhone OS 11.3 (15E216)
Baseband Version: 1.89.00
Report Version: 104

Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001825d8d10
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread: 18

Application Specific Information:
BUG IN LIBDISPATCH: Unexpected error from mach_msg_receive
Abort Cause 268451847

Filtered syslog:
None found

Thread 18 name: Dispatch queue: com.apple.main-thread
Thread 18 Crashed:
0 libdispatch.dylib 0x00000001825d8d10 _dispatch_mach_send_and_wait_for_reply + 1544
1 libdispatch.dylib 0x00000001825d8938 _dispatch_mach_send_and_wait_for_reply + 560
2 libdispatch.dylib 0x00000001825d8e30 dispatch_mach_send_with_result_and_wait_for_reply$VARIANT$armv81 + 56
3 libxpc.dylib 0x00000001829148d8 xpc_connection_send_message_with_reply_sync + 196
4 CoreFoundation 0x0000000182c4ed08 __80-[CFPrefsSearchListSource alreadylocked_generationCountFromListOfSources:count:]_block_invoke_3.143 + 40
5 CoreFoundation 0x0000000182cf5d04 -[_CFXPreferences withConnectionForRole:performBlock:] + 48
6 CoreFoundation 0x0000000182c4ecd4 __80-[CFPrefsSearchListSource alreadylocked_generationCountFromListOfSources:count:]_block_invoke_2.142 + 124
7 libsystem_trace.dylib 0x00000001828f5c70 _os_activity_initiate_impl + 60
8 CoreFoundation 0x0000000182c4ec2c __80-[CFPrefsSearchListSource alreadylocked_generationCountFromListOfSources:count:]_block_invoke.140 + 124
9 CoreFoundation 0x0000000182c4e74c CFPREFERENCES_IS_WAITING_FOR_SYSTEM_CFPREFSD + 48
10 CoreFoundation 0x0000000182c4e984 -[CFPrefsSearchListSource alreadylocked_generationCountFromListOfSources:count:] + 184
11 CoreFoundation 0x0000000182c4f238 -[CFPrefsSearchListSource alreadylocked_copyDictionary] + 384
12 CoreFoundation 0x0000000182ceac58 -[CFPrefsSource copyDictionary] + 56
13 CoreFoundation 0x0000000182c4f088 -[CFPrefsSearchListSource generationCount] + 48
14 CoreFoundation 0x0000000182c4f020 -[CFPrefsSearchListSource handleRemoteChangeNotificationForDomainIdentifier:] + 308
15 CoreFoundation 0x0000000182ce9a34 -[CFPrefsSource forEachObserver:] + 288
16 CoreFoundation 0x0000000182cea100 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:from:] + 348
17 CoreFoundation 0x0000000182cea304 -[CFPrefsSource setValue:forKey:from:] + 64
18 CoreFoundation 0x0000000182ceb55c -[_CFXPreferences+ 1566044 (SourceAdditions) withSourceForIdentifier:user:byHost:container:cloud:perform:] + 744
19 CoreFoundation 0x0000000182c50334 -[_CFXPreferences+ 930612 (SearchListAdditions) with23930198HackSourceForIdentifier:user:byHost:container:cloud:perform:] + 360
20 CoreFoundation 0x0000000182cf4810 -[_CFXPreferences setValue:forKey:identifier:user:host:container:] + 160
21 CoreFoundation 0x0000000182bfb7ec CFPreferencesSetValue + 136
22 ...56963a9152.dylib.arch_arm64 0x000000010cd18b30 0x10cd0c000 + 52016
23 libobjc.A.dylib 0x0000000181e6e9f0 call_load_methods + 184
24 libobjc.A.dylib 0x0000000181e6fb58 load_images + 76
25 dyld 0x00000001012f20c8 dyld::notifySingle+ 8392 (dyld_image_states, ImageLoader const*, ImageLoader::InitializerTimingList*) + 384
26 dyld 0x000000010130212c ImageLoader::recursiveInitialization+ 74028 (ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 440
27 dyld 0x00000001013011cc ImageLoader::processInitializers+ 70092 (ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 136
28 dyld 0x0000000101301288 ImageLoader::runInitializers+ 70280 (ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 84
29 dyld 0x00000001012f5614 dyld::runInitializers+ 22036 (ImageLoader*) + 88
30 dyld 0x00000001012fb934 dlopen + 1024
31 libdyld.dylib 0x000000018260aef0 dlopen + 116
32 libdyld.dylib 0x000000018260b118 _dyld_find_unwind_sections + 136

Thread 18 crashed with ARM Thread State (64-bit):
x0: 0x0000000010004007 x1: 0x000000000400400e x2: 0x0000000000000000 x3: 0x0000000000004000
x4: 0x0000000000001603 x5: 0x0000000000000000 x6: 0x0000000000002503 x7: 0x00000000000003e2
x8: 0x0000000010004007 x9: 0x000000000400400e x10: 0x0000000141054000 x11: 0x0000000140ffbf80
x12: 0x0000000000000018 x13: 0x0000000010000004 x14: 0x0000000000100031 x15: 0x0000000000000000
x16: 0xffffffffffffffe1 x17: 0xffffffd0ffffffff x18: 0x0000000000000000 x19: 0x00000000efffbffe
x20: 0x0000000140ff7f80 x21: 0x0000000000004000 x22: 0x0000000000000000 x23: 0x0000000140ff7f80
x24: 0x0000000000001603 x25: 0x0000000000000000 x26: 0x0000000000002503 x27: 0x000000000400400e
x28: 0x00000001825d8dd8 fp: 0x0000000140ffc0a0 lr: 0x00000001825d8938
sp: 0x0000000140ff7f80 pc: 0x00000001825d8d10 cpsr: 0x80000000

Error, no Team ID. Wat.

Hi its me again. I used the newest version, and now it says that there is no teamid. Starting from line 122, I ran jtool --sig --ent "$BINARY" (which the shell code itself does) and it shows all of the information for the signature, so it must be something with the shell code after it - 2> /dev/null | grep 'Team ID' | head -n1 |sed 's/ //g'|cut -f2 -d:|cut -f1 -d(`. As I am no shell code guru I am stuck again, any help?

[!] Unknown jailbreak. Aborting.

Using bfinject on an iPhone 6S running iOS 11.1.2 and LiberiOS 11.0.3 results in "[!] Unknown jailbreak. Aborting.".
Any ideas on that?

md5sum: command not found

Hi, after last update Core Utilities (8.29-1) it stopped working again. Now md5sum is not found. What now? Thanks

iPhone:~/bfinject root# bash bfinject -p 1566 -L test
[+] Electra detected.
bfinject: line 172: md5sum: command not found
bfinject: line 173: md5sum: command not found
cp: '/electra/usr/local/bin/bfinject4realz' and '/electra/usr/local/bin/bfinject4realz' are the same file
bfinject: line 184: tail: command not found
bfinject: line 184: cut: command not found
[+] Injecting into ''
[+] Getting Team ID from target application...
bfinject: line 199: tail: command not found
bfinject: line 199: cut: command not found
bfinject: line 199: cut: command not found
[+] WARNING: No Team ID found. Continuing regardless, but expect weird stuff to happen.
[+] Thinning dylib into non-fat arm64 image
[+] Signing injectable .dylib with Team ID and platform entitlements...
jtool /electra/usr/local/bin/ signing error. barfing.

dlopen no suitable image found

Using latest commit on i7 11.1, with LiberiOS 11.0.3:

bash bfinject -p 813 -l /jb/bfinject/test.dylib
[+] Injecting into '/var/containers/Bundle/Application/E7C4881E-DA00-4DE0-83B1-463896AECD42/Twitter.app/Twitter'
[+] Getting Team ID from target application...
[+] Signing injectable .dylib with Team ID N66CZ3Y3BX and platform entitlements...
[+] Injecting /jb/bfinject/test.dylib into target application, PID 813
[+] LiberiOS assumed. Using Bishop Fox bfinject to inject the dylib
[bfinject] Getting tfp.
[bfinject] Creating new remote thread
[bfinject] Thread ID: 3075 (0xc03)
[bfinject] Looking for RET gadget in the target app...
gadget candidate: 0x104f27db8 ... Found @ 0x104f27db8
[bfinject] Fake stack frame is 536870912 bytes at 0x11536c000 in remote proc
[bfinject] Looking for '_pthread_set_self' in the target process...
[bfinject] Desired function '_pthread_set_self' is at 0x185ee3804
[bfinject] Setting registers with destination function
[bfinject] New CPU state:
$pc = 0x185ee3804
$sp = 0x12d36c000
$x0 = 0x0
$x1 = 0x0
$x2 = 0x0
$x3 = 0x0
[bfinject] Resuming thread with hijacked regs
[bfinject] Waiting for thread to hit the infinite loop gadget...
[bfinject] We hit the infinite loop, call complete. Restoring stack and registers.
[bfinject] Looking for 'dlopen' in the target process...
[bfinject] Desired function 'dlopen' is at 0x185ca3460
[bfinject] Setting registers with destination function
[bfinject] New CPU state:
$pc = 0x185ca3460
$sp = 0x12d36c000
$x0 = 0x11536c000
$x1 = 0xa
$x2 = 0x0
$x3 = 0x0
[bfinject] Resuming thread with hijacked regs
[bfinject] Waiting for thread to hit the infinite loop gadget...
[bfinject] We hit the infinite loop, call complete. Restoring stack and registers.
[bfinject] dlopen() returned 0x0 (FAILURE)
[bfinject] Looking for 'dlerror' in the target process...
[bfinject] Desired function 'dlerror' is at 0x185ca32b0
[bfinject] Setting registers with destination function
[bfinject] New CPU state:
$pc = 0x185ca32b0
$sp = 0x12d36c000
$x0 = 0x0
$x1 = 0x0
$x2 = 0x0
$x3 = 0x0
[bfinject] Resuming thread with hijacked regs
[bfinject] Waiting for thread to hit the infinite loop gadget...
[bfinject] We hit the infinite loop, call complete. Restoring stack and registers.
[bfdecrypt] dlerror() returned: dlopen(/System/Library/Frameworks/ec5c0d1e8fc4688149972a6c2426cb34.framework/ec5c0d1e8fc4688149972a6c2426cb34.dylib, 10): no suitable image found. Did find:
/System/Library/Frameworks/ec5c0d1e8fc4688149972a6c2426cb34.framework/ec5c0d1e8fc4688149972a6c2426cb34.dylib: code signature invalid for '/System/Library/Frameworks/ec5c0d1e8fc4688149972a6c2426cb34.framework/ec5c0d1e8fc4688149972a6c2426cb34.dylib'

[+] So long and thanks for all the fish.

jtool dylib signing error

Getting this error on i7 11.1, running LiberiOS 11.0.3:

-bash-3.2# bash bfinject -p 813 -l /jb/bfinject/test.dylib
[+] Injecting into '/var/containers/Bundle/Application/E7C4881E-DA00-4DE0-83B1-463896AECD42/Twitter.app/Twitter'
[+] Getting Team ID from target application...
[+] Signing injectable .dylib with Team ID com.atebits.Tweetie2 and platform entitlements...
jtool dylib signing error. barfing.
total 264
-rwxr-xr-x  1 root  wheel  133216 Jan 23 16:56 bffd24d9a145056f32ee3b9599c3a3c8.dylib

Load into SpringBoard

When trying to load into SpringBoard it says

A-iP6S:/var/mobile/Documents/bfinject root# bash bfinject -P SpringBoard -L cycript
[!] "SpringBoard" was not uniquely found, please check your criteria.

Is this intentional? Perhaps write a note on the README and shortly explain why might be a good idea? Just a suggestion though.

mach_vm_map(size=6123749376) failed (error code=3)

[bfinject4realz] Calling dlopen() at 0x180cdee7c... [bfinject4realz] Returned from 'dlopen' [bfinject4realz] ERROR: dlopen() failed to load the dylib.returned 0x0 (FAILURE) [bfinject4realz] Calling dlerror() at 0x180cdeccc... [bfinject4realz] Returned from 'dlerror' 4bd5fbead65852c23bb3956d335cfa55 -(4117,0x1b358ab40) malloc: *** mach_vm_map(size=6123749376) failed (error code=3) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug [bfinject4realz] dlerror() returned: (null)
App: https://itunes.apple.com/de/app/sparkasse-ihre-mobile-filiale/id320599923?mt=8
App only opens if Tweak Mode is disabled

Thread_create() returned 4, errno =2

Error is in the title. It happens no matter what app I try it on and I’ve tried restarting, rejailbreaking, all that jazz, none of its helped. The command I’m running is “bash bfinject -P Reddit.app -L test”. Any idea as to what’s up?

Æ!Å Unknown jailbreak. Aborting.

Platform: Electra Latest (With all updates and dev tools from the repo)

The issue I am getting is the following

$ root# bash bfinject -P BAFlights -L decrypt
Æ!Å Unknown jailbreak. Aborting.

jtool dylib signing error. barfing.

This error gets thrown while I try to decrypt applications. I believe this issue is due to the .dylib not being signed.

[+] Injecting into '/var/containers/Bundle/Application/D98C23B4-8B41-49E8-9858-B46B77D770DD/Reddit.app/Reddit'
[+] Getting Team ID from target application...
[+] Signing injectable .dylib with Team ID com.reddit.Reddit and platform entitlements...
jtool dylib signing error. barfing.

Upon reviewing the code, line 159 : jtool --sign platform --ent entitlements.xml --inplace --teamid $TEAMID $DYLIB_PATH > /dev/null 2>&1 is where the error occurs. Specifically, the platform and --teamid are what cause the errors. tool doesn't recognize those two arguments.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.