SlideShare a Scribd company logo
Function Hooking with Xposed
Jaime Geiger
1
http://tiny.cc/bsidesroc-xposed
Agenda
● Intro - whoami, whoareyou, what is xposed?
● Tools (brief) - JD-gui, jad, apktool, aapt, dex2jar
● What to hook - making sense of obfuscation, finding the right function to
hook
● Basic hooks - hooking code, changing return values/parameters
● Reversing - making the app do the work, dumping API keys
● Disabling Security Checks - certificate pinning
2
Intro: Formalities and Background
3
# whoami
● @jgeigerm / wumb0 - wumb0.in
● InfoSec @ RIT (or CSEC, whatever)
● Working for Grimm after graduation in VA (grimm-co.com)
● Hobbies/Interests:
○ CTFs, Reversing, Exploitation
○ Collecting acronyms: RC3, KDR, CCDC, SI, R2D2, ACDC, etc. etc.
○ Poking android (in all the right places )
○ Red team & malware development
4
# who -u
● RIT Students?
● Java programmers?
● Android users?
● Android application programmers?
● Used xposed before?
● Written xposed modules before?
● None of the above?
5
What’s an Xposed? Sounds hot.
● Function and resource hooking framework
○ Modify functions (returns, parameters, exceptions) & UI elements
● Written and maintained by rovo89 (GitHub)
● Replaces app_process to allow access to ART/Dalvik
● It is hot!
6
How does xposed work?
● Does not change an app’s signature
● Replacement app_process that adds a jar to the java classpath
○ service zygote /system/bin/app_process -Xzygote /system/bin
--zygote --start-system-server
○ All processes are forked from zygote - hook zygote, hook all
apps!
○ Jar added is the xposedbridge!
● (Yes you need root to do this!)
7
Tools: they live among us
8
JD-GUI/jad
9
● Java decompilers
● JD-GUI takes jar/class files and has a browser
● Jad takes class files only
○ but better decompilation, IMO
dex2jar/apktool
● dex2jar converts dex (classes in an APK) into JAR
● apktool extracts smali (Java bytecode) and resources from an
APK
10
aapt
● Part of build-tools in the Android SDK
● Lets you see resources inside an APK without unpacking it
● Decompiled code has references to string values by number
○ Jad has them in hex
○ JD-GUI has them in decimal
● Need this to search strings completely
aapt d strings the.apk | grep “looking for this string”
11
Custom Tools to help!
● apkdecompile.sh - unpacks and decompiles all classes in APK
○ Requires dex2jar and jad
○ Has a --shitty option (see unzipshittyobfuscatedjar.sh...)
● searchstring.sh - search a string value in an APK by hex or
decimal number
○ Requires aapt
● unzipshittyobfuscatedjar.sh - sometimes obfuscated class names
are Aa.class AND AA.class AND aa.class
● Find them here
12
What to hook: digging through source!
13
Process
14
1. Get the apk
○ @ www.apk4fun.com (pls no piracy) or /data/app on device
2. Convert to JAR (d2j-dex2jar the.apk) and extract (apktool d
the.apk)
3. Decompile with jad or jd-gui
4. (maybe) smash head against obfuscation
○ Look at strings, related functions, etc.
5. Identify relevant classes and functions
Basic Hooks: Getting up in there
15
Important imports!
● XposedBridge.jar - contains all necessary classes for module dev
● XposedHelpers.findAndHookMethod
● XposedHelpers.callMethod
● IXposedHookLoadPackage - base class loaded on app init
● XC_MethodReplacement/XC_MethodHook
● Callbacks.XC_LoadPackage.LoadPackageParam - package
information
● XposedBridge - helpers (logging)
16
Xposed Project Module Structure
libs/XposedBridge.jar -> ../XposedBridge/app/build/intermediates/packaged/release/classes.jar
build.gradle - root project build file
Local.properties - specifies Android SDK directory
app/
build.gradle - details module, includes XposedBridge from libs
src/main
AndroidManifest.xml - defines the app permissions and such
assets/xposed_init - tells xposed what class to run on start
res/ - any resources you need (strings, layouts, etc.)
java/your/company/appname/Hooks.java - hooks to install
See xposed skeleton creator in the GitHub repo for this talk! 17
Side Note: Building and Installing Modules
● Build with gradle (gradle build)
● Output APK is at app/build/outputs/apk/app-debug.apk
○ Feel free to sign it
● adb install -r app/build/outputs/apk/app-debug.apk
18
Package hooking skeleton
public class Hooks implements IXposedHookLoadPackage {
public void handleLoadPackage(final LoadPackageParam lpparam)
throws Throwable {
if (!lpparam.packageName.equals("the.package.name"))
return;
//find and hook methods here
}
}
19
findAndHookMethod
● Finds a class method by name and hooks it with whatever you
want
1. Return a constant
2. Ignore it completely
3. Do something before the function is called
4. Do something else instead
5. Do something after the function is called successfully
findAndHookMethod(“com.app.classname”, lpparam.classLoader,
“functionName”, [func arg1 class], [func arg2 class], hook);
20
Scenario 1: Make a function return a constant value
● We want verifyPasscode(String passcode) in class com.bank.
app.Main to always return true
○ Assume it returns a boolean
findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader,
“verifyPasscode”, String.class, XC_MethodReplacement.returnConstant
(true));
21
Scenario 2: Ignore the function completely
● We want checkSecurity() in class com.bank.app.Main to be
ignored
○ Mostly used with void functions!
findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader,
“checkSecurity”, XC_MethodReplacement.DO_NOTHING);
22
Scenario 3: Do something before the function is called
● We want to check the parameter for function transferFunds
(String toAccount) in class com.bank.app.Main and change it
23
Scenario 3: Do something before the function is called
findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader,
“transferFunds”, String.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod (MethodHookParam param) throws
Throwable {
param.args[0] = “12345678”;
XposedBridge.log(“changed account number!!”);
}
});
24
Scenario 4: Do something else instead
● We want checkPasswordOK(String password) in class com.
bank.app.Main to always return true, but also dump to the logs.
○ Assuming the function returns a boolean
25
Scenario 4: Do something else instead
findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader,
“checkPasswordOK”, String.class, new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param)
throws Throwable {
XposedBridge.log((String)param.args[0]);
return true;
}
});
26
Scenario 5: Do something after the function is called
● We want to get the return value of generateToken() in class
com.bank.app.Main and dump it to the logs
○ Assuming it returns a string with the token
27
Scenario 5: Do something after the function is called
findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader,
“generateToken”, new XC_MethodHook() {
@Override
protected void afterHookedMethod (MethodHookParam param) throws
Throwable {
XposedBridge.log((String)param.getResult());
}
});
28
Practical Example & Demo: Words With Friends
Word checking is done client side, so we’ll disable the check
1. Decompile/unpack
2. Find where word validation is done
3. Hook function to always return true (XC_MethodReplacement)
4. Cheat!
29
gnireenignE: Extracting information, understanding code
30
Getting to the Goods
● Obfuscated code/variables/keys can be annoying to find in an
app
● If the app checks it’s own signature decompiling, editing, and
recompiling is ruled out
● Dump variables to the logs after they have been
deobfuscated/calculated
31
Practical Example & Demo: Yik Yak
32
● API key is calculated based on the app’s signature (YikYak.a)
● getBytes method is used on the variable when requests are
being signed (post calculation)
○ Part of java.lang.String
● Dump key out to the logs, acquire API key, make requests with
python!
● And yes, every time they update the app, the obfuscation
changes...
Disabling Security Checks: we don’t need them
33
Android Application Auditing
34
● Man-in-the-middle-ing is useful
○ If the app employs certificate pinning you are out of luck
○ Alternative method is static code analysis
● You can disable certificate pinning with xposed!
Practical Example & Demo: Yik Yak (pt. 2)
35
● SSLPeerUnverifiedException is thrown if the certificate is
invalid
○ A few hours of reversing told me this. I’ll spare you that demo :)
● Find the SSLPeerUnverifiedException, hook the function it’s
thrown in, and cert pinning goes away
● Let’s MITM
Other Resources and Code
36
● Code from this presentation: rev_tools, xposed_mods
● rovo89’s module development tutorial
● XDA forum for xposed modules and development
● Xposed source code
● Snapprefs source code
Questions?
37

More Related Content

What's hot

Clean code & design patterns
Clean code & design patternsClean code & design patterns
Clean code & design patterns
Pascal Larocque
 
The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)
jeresig
 
Jeff English: Demystifying Module Development - How to Extend Titanium
Jeff English: Demystifying Module Development - How to Extend TitaniumJeff English: Demystifying Module Development - How to Extend Titanium
Jeff English: Demystifying Module Development - How to Extend Titanium
Axway Appcelerator
 
Javascript The Good Parts v2
Javascript The Good Parts v2Javascript The Good Parts v2
Javascript The Good Parts v2
Federico Galassi
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
Rowan Merewood
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lv
Anton Arhipov
 
Design Patterns in Game Programming
Design Patterns in Game ProgrammingDesign Patterns in Game Programming
Design Patterns in Game Programming
Bruno Cicanci
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
jigeno
 
Introduction to Frida
Introduction to FridaIntroduction to Frida
Introduction to Frida
AbhishekJaiswal270
 
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8
Victor Rentea
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for Programmers
David Rodenas
 
Pentesting Android Apps using Frida (Beginners)
Pentesting Android Apps using Frida (Beginners)Pentesting Android Apps using Frida (Beginners)
Pentesting Android Apps using Frida (Beginners)
Chandrapal Badshah
 
Exception Handling in the C++ Constructor
Exception Handling in the C++ ConstructorException Handling in the C++ Constructor
Exception Handling in the C++ Constructor
Somenath Mukhopadhyay
 
Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Testing untestable code - ConFoo13
Testing untestable code - ConFoo13
Stephan Hochdörfer
 
The bytecode gobbledygook
The bytecode gobbledygookThe bytecode gobbledygook
The bytecode gobbledygook
Raimon Ràfols
 

What's hot (15)

Clean code & design patterns
Clean code & design patternsClean code & design patterns
Clean code & design patterns
 
The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)
 
Jeff English: Demystifying Module Development - How to Extend Titanium
Jeff English: Demystifying Module Development - How to Extend TitaniumJeff English: Demystifying Module Development - How to Extend Titanium
Jeff English: Demystifying Module Development - How to Extend Titanium
 
Javascript The Good Parts v2
Javascript The Good Parts v2Javascript The Good Parts v2
Javascript The Good Parts v2
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lv
 
Design Patterns in Game Programming
Design Patterns in Game ProgrammingDesign Patterns in Game Programming
Design Patterns in Game Programming
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
 
Introduction to Frida
Introduction to FridaIntroduction to Frida
Introduction to Frida
 
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for Programmers
 
Pentesting Android Apps using Frida (Beginners)
Pentesting Android Apps using Frida (Beginners)Pentesting Android Apps using Frida (Beginners)
Pentesting Android Apps using Frida (Beginners)
 
Exception Handling in the C++ Constructor
Exception Handling in the C++ ConstructorException Handling in the C++ Constructor
Exception Handling in the C++ Constructor
 
Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Testing untestable code - ConFoo13
Testing untestable code - ConFoo13
 
The bytecode gobbledygook
The bytecode gobbledygookThe bytecode gobbledygook
The bytecode gobbledygook
 

Similar to BSidesROC 2016 - Jaime Geiger - Android Application Function Hooking With Xposed

Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
Frida  Android run time hooking - Bhargav Gajera & Vitthal ShindeFrida  Android run time hooking - Bhargav Gajera & Vitthal Shinde
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
NSConclave
 
Pwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreakPwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreak
Abraham Aranguren
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
RichardWarburton
 
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
GuardSquare
 
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon Berlin
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
Andrea Righi
 
Modern c++
Modern c++Modern c++
Dynamic PHP web-application analysis
Dynamic PHP web-application analysisDynamic PHP web-application analysis
Dynamic PHP web-application analysis
ax330d
 
Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"
Kiwamu Okabe
 
Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018
Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018
Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018
Andy Davies
 
Oleksandr Tarasenko "ORM vs GraphQL"
Oleksandr Tarasenko "ORM vs GraphQL"Oleksandr Tarasenko "ORM vs GraphQL"
Oleksandr Tarasenko "ORM vs GraphQL"
Fwdays
 
ORM vs GraphQL - Python fwdays 2019
ORM vs GraphQL - Python fwdays 2019ORM vs GraphQL - Python fwdays 2019
ORM vs GraphQL - Python fwdays 2019
Oleksandr Tarasenko
 
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
Paris Open Source Summit
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii Shapoval
GlobalLogic Ukraine
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Tom Keetch
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
GWTcon
 
Automated malware analysis
Automated malware analysisAutomated malware analysis
Automated malware analysis
Ibrahim Baliç
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CanSecWest
 
Naive application development
Naive application developmentNaive application development
Naive application development
Shaka Huang
 
idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...
idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...
idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...
idsecconf
 

Similar to BSidesROC 2016 - Jaime Geiger - Android Application Function Hooking With Xposed (20)

Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
Frida  Android run time hooking - Bhargav Gajera & Vitthal ShindeFrida  Android run time hooking - Bhargav Gajera & Vitthal Shinde
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
 
Pwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreakPwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreak
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
 
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
Modern c++
Modern c++Modern c++
Modern c++
 
Dynamic PHP web-application analysis
Dynamic PHP web-application analysisDynamic PHP web-application analysis
Dynamic PHP web-application analysis
 
Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"
 
Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018
Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018
Inspecting iOS App Traffic with JavaScript - JSOxford - Jan 2018
 
Oleksandr Tarasenko "ORM vs GraphQL"
Oleksandr Tarasenko "ORM vs GraphQL"Oleksandr Tarasenko "ORM vs GraphQL"
Oleksandr Tarasenko "ORM vs GraphQL"
 
ORM vs GraphQL - Python fwdays 2019
ORM vs GraphQL - Python fwdays 2019ORM vs GraphQL - Python fwdays 2019
ORM vs GraphQL - Python fwdays 2019
 
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii Shapoval
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
Automated malware analysis
Automated malware analysisAutomated malware analysis
Automated malware analysis
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
 
Naive application development
Naive application developmentNaive application development
Naive application development
 
idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...
idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...
idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...
 

Recently uploaded

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 

Recently uploaded (20)

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 

BSidesROC 2016 - Jaime Geiger - Android Application Function Hooking With Xposed

  • 1. Function Hooking with Xposed Jaime Geiger 1 http://tiny.cc/bsidesroc-xposed
  • 2. Agenda ● Intro - whoami, whoareyou, what is xposed? ● Tools (brief) - JD-gui, jad, apktool, aapt, dex2jar ● What to hook - making sense of obfuscation, finding the right function to hook ● Basic hooks - hooking code, changing return values/parameters ● Reversing - making the app do the work, dumping API keys ● Disabling Security Checks - certificate pinning 2
  • 3. Intro: Formalities and Background 3
  • 4. # whoami ● @jgeigerm / wumb0 - wumb0.in ● InfoSec @ RIT (or CSEC, whatever) ● Working for Grimm after graduation in VA (grimm-co.com) ● Hobbies/Interests: ○ CTFs, Reversing, Exploitation ○ Collecting acronyms: RC3, KDR, CCDC, SI, R2D2, ACDC, etc. etc. ○ Poking android (in all the right places ) ○ Red team & malware development 4
  • 5. # who -u ● RIT Students? ● Java programmers? ● Android users? ● Android application programmers? ● Used xposed before? ● Written xposed modules before? ● None of the above? 5
  • 6. What’s an Xposed? Sounds hot. ● Function and resource hooking framework ○ Modify functions (returns, parameters, exceptions) & UI elements ● Written and maintained by rovo89 (GitHub) ● Replaces app_process to allow access to ART/Dalvik ● It is hot! 6
  • 7. How does xposed work? ● Does not change an app’s signature ● Replacement app_process that adds a jar to the java classpath ○ service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server ○ All processes are forked from zygote - hook zygote, hook all apps! ○ Jar added is the xposedbridge! ● (Yes you need root to do this!) 7
  • 8. Tools: they live among us 8
  • 9. JD-GUI/jad 9 ● Java decompilers ● JD-GUI takes jar/class files and has a browser ● Jad takes class files only ○ but better decompilation, IMO
  • 10. dex2jar/apktool ● dex2jar converts dex (classes in an APK) into JAR ● apktool extracts smali (Java bytecode) and resources from an APK 10
  • 11. aapt ● Part of build-tools in the Android SDK ● Lets you see resources inside an APK without unpacking it ● Decompiled code has references to string values by number ○ Jad has them in hex ○ JD-GUI has them in decimal ● Need this to search strings completely aapt d strings the.apk | grep “looking for this string” 11
  • 12. Custom Tools to help! ● apkdecompile.sh - unpacks and decompiles all classes in APK ○ Requires dex2jar and jad ○ Has a --shitty option (see unzipshittyobfuscatedjar.sh...) ● searchstring.sh - search a string value in an APK by hex or decimal number ○ Requires aapt ● unzipshittyobfuscatedjar.sh - sometimes obfuscated class names are Aa.class AND AA.class AND aa.class ● Find them here 12
  • 13. What to hook: digging through source! 13
  • 14. Process 14 1. Get the apk ○ @ www.apk4fun.com (pls no piracy) or /data/app on device 2. Convert to JAR (d2j-dex2jar the.apk) and extract (apktool d the.apk) 3. Decompile with jad or jd-gui 4. (maybe) smash head against obfuscation ○ Look at strings, related functions, etc. 5. Identify relevant classes and functions
  • 15. Basic Hooks: Getting up in there 15
  • 16. Important imports! ● XposedBridge.jar - contains all necessary classes for module dev ● XposedHelpers.findAndHookMethod ● XposedHelpers.callMethod ● IXposedHookLoadPackage - base class loaded on app init ● XC_MethodReplacement/XC_MethodHook ● Callbacks.XC_LoadPackage.LoadPackageParam - package information ● XposedBridge - helpers (logging) 16
  • 17. Xposed Project Module Structure libs/XposedBridge.jar -> ../XposedBridge/app/build/intermediates/packaged/release/classes.jar build.gradle - root project build file Local.properties - specifies Android SDK directory app/ build.gradle - details module, includes XposedBridge from libs src/main AndroidManifest.xml - defines the app permissions and such assets/xposed_init - tells xposed what class to run on start res/ - any resources you need (strings, layouts, etc.) java/your/company/appname/Hooks.java - hooks to install See xposed skeleton creator in the GitHub repo for this talk! 17
  • 18. Side Note: Building and Installing Modules ● Build with gradle (gradle build) ● Output APK is at app/build/outputs/apk/app-debug.apk ○ Feel free to sign it ● adb install -r app/build/outputs/apk/app-debug.apk 18
  • 19. Package hooking skeleton public class Hooks implements IXposedHookLoadPackage { public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable { if (!lpparam.packageName.equals("the.package.name")) return; //find and hook methods here } } 19
  • 20. findAndHookMethod ● Finds a class method by name and hooks it with whatever you want 1. Return a constant 2. Ignore it completely 3. Do something before the function is called 4. Do something else instead 5. Do something after the function is called successfully findAndHookMethod(“com.app.classname”, lpparam.classLoader, “functionName”, [func arg1 class], [func arg2 class], hook); 20
  • 21. Scenario 1: Make a function return a constant value ● We want verifyPasscode(String passcode) in class com.bank. app.Main to always return true ○ Assume it returns a boolean findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader, “verifyPasscode”, String.class, XC_MethodReplacement.returnConstant (true)); 21
  • 22. Scenario 2: Ignore the function completely ● We want checkSecurity() in class com.bank.app.Main to be ignored ○ Mostly used with void functions! findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader, “checkSecurity”, XC_MethodReplacement.DO_NOTHING); 22
  • 23. Scenario 3: Do something before the function is called ● We want to check the parameter for function transferFunds (String toAccount) in class com.bank.app.Main and change it 23
  • 24. Scenario 3: Do something before the function is called findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader, “transferFunds”, String.class, new XC_MethodHook() { @Override protected void beforeHookedMethod (MethodHookParam param) throws Throwable { param.args[0] = “12345678”; XposedBridge.log(“changed account number!!”); } }); 24
  • 25. Scenario 4: Do something else instead ● We want checkPasswordOK(String password) in class com. bank.app.Main to always return true, but also dump to the logs. ○ Assuming the function returns a boolean 25
  • 26. Scenario 4: Do something else instead findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader, “checkPasswordOK”, String.class, new XC_MethodReplacement() { @Override protected Object replaceHookedMethod(MethodHookParam param) throws Throwable { XposedBridge.log((String)param.args[0]); return true; } }); 26
  • 27. Scenario 5: Do something after the function is called ● We want to get the return value of generateToken() in class com.bank.app.Main and dump it to the logs ○ Assuming it returns a string with the token 27
  • 28. Scenario 5: Do something after the function is called findAndHookMethod(“com.bank.app.Main”, lpparam.classLoader, “generateToken”, new XC_MethodHook() { @Override protected void afterHookedMethod (MethodHookParam param) throws Throwable { XposedBridge.log((String)param.getResult()); } }); 28
  • 29. Practical Example & Demo: Words With Friends Word checking is done client side, so we’ll disable the check 1. Decompile/unpack 2. Find where word validation is done 3. Hook function to always return true (XC_MethodReplacement) 4. Cheat! 29
  • 30. gnireenignE: Extracting information, understanding code 30
  • 31. Getting to the Goods ● Obfuscated code/variables/keys can be annoying to find in an app ● If the app checks it’s own signature decompiling, editing, and recompiling is ruled out ● Dump variables to the logs after they have been deobfuscated/calculated 31
  • 32. Practical Example & Demo: Yik Yak 32 ● API key is calculated based on the app’s signature (YikYak.a) ● getBytes method is used on the variable when requests are being signed (post calculation) ○ Part of java.lang.String ● Dump key out to the logs, acquire API key, make requests with python! ● And yes, every time they update the app, the obfuscation changes...
  • 33. Disabling Security Checks: we don’t need them 33
  • 34. Android Application Auditing 34 ● Man-in-the-middle-ing is useful ○ If the app employs certificate pinning you are out of luck ○ Alternative method is static code analysis ● You can disable certificate pinning with xposed!
  • 35. Practical Example & Demo: Yik Yak (pt. 2) 35 ● SSLPeerUnverifiedException is thrown if the certificate is invalid ○ A few hours of reversing told me this. I’ll spare you that demo :) ● Find the SSLPeerUnverifiedException, hook the function it’s thrown in, and cert pinning goes away ● Let’s MITM
  • 36. Other Resources and Code 36 ● Code from this presentation: rev_tools, xposed_mods ● rovo89’s module development tutorial ● XDA forum for xposed modules and development ● Xposed source code ● Snapprefs source code