Attempting to brute force Android security pattern through TWRP via adb


Question

Yesterday I somehow forgot the Android security pattern on my phone. Due to muscle memory I sort of know what it was, but can't figure out the true pattern. Therefore I'm attempting to brute force it to allow me to unlock the phone again.



Decrypt with pattern

Since I've TWRP recovery installed, I'm able to use the twrp decrypt 'passphrase' command for decryption attempts. I'm using a 4x4 pattern (OnePlus5, LineageOS, Android 8.1, TWRP clockworkx 3.2.3-1) for which each dot in the grid translates to a different character, you should concatenate to build your passphrase. I believe the 4x4 grid looks like this:



1
2
3
4
5 6 7 8
9 : ; <
= > ? @


Having a line pattern from the top left to the bottom right would give a passphrase of 16;@, allowing you to decrypt your phone in TWRP using adb shell twrp decrypt '16;@'. (via)



Brute force attempt

Through this method I've attempted all possible patterns I believe could be it, but I didn't succeed decrypting it. The command always returns Attempting to decrypt data partition via command line. to stdout, and nothing else. I'm rapidly attempting each pattern one after the other with no delay, detecting whether any command output differs from the expected output (which hasn't happened yet).



Questions

Because I didn't succeed yet, I'm wondering if my implementation is correct. I don't have a phone to test with, so I have a few questions:




  1. Does the twrp decrypt command output something else when decryption succeeds?

  2. Does successfully decrypting create a block device at /dev/block/dm-0, which I can probe for?

  3. Should I wait a few seconds after each attempt before probing for success?

  4. Is there some sort of hidden timeout (required to wait 30 seconds after attempt)?

  5. Is there another method I can use to probe for success?



Brute force tool

I did build the following tool for this brute force attempt, if that's relevant for what implementation I've used: apbf



I don't understand what is wrong with this implementation. It does not seems to properly decrypt the phone, making me wonder if the key could be corrupted.



I'm currently rebooting recovery after reach attempt, but that takes a lot of time for 1400 possible patterns. I'd like to be sure the attempt isn't useless.






Since I do know the approximate pattern length, am certain only the two right columns are used, and know that the dots in the pattern never have a distance greater than 1, I can greatly reduce the pattern search space and limit the possibilities.



Encryption is enabled on the phone, I believe it's file-based. When in TWRP, the /data/data and /sdcard directory seems to list encrypted file names.


Answer

After a while I figured out what the problem was, with a freshly flashed phone. Here I'll be answering my own question.








  1. Does the twrp decrypt command output something else when decryption succeeds?




    Yes, it outputs something like:



    Attempting to decrypt data partition via command line.
    Data successfully decrypted
    Updating partition details...
    ...done


  2. Does successfully decrypting create a block device at /dev/block/dm-0, which I can probe for?




    No.



  3. Should I wait a few seconds after each attempt before probing for success?




    -



  4. Is there some sort of hidden timeout (required to wait 30 seconds after attempt)?




    Yes, very important! About 10 seconds. Consecutive attempts within that time frame fail with no warning whatsoever.



  5. Is there another method I can use to probe for success?




    -







So, consecutive attempts to invoke twrp decrypt must have at least 10 seconds between them or else they will fail. So, the only thing that was wrong with the developed tool, is that I didn't implement this timeout.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes