android mobile pentest 101 · java.use(‘com.android.insecurebankv2.postlogin’) - sau đó thì...
TRANSCRIPT
![Page 1: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/1.jpg)
AndroidMobilePentest 101©tsug0d,September2018
![Page 2: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/2.jpg)
Bài7– HookingVớiFridaMụctiêu:SửdụngđượcFridađểhook
![Page 3: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/3.jpg)
- LàmộtDynamicinstrumentation (tracing,profiling, vàdebugging trong lúcappchạy)toolkitchodevelopers, reverse-engineers,vàsecurityresearchers.
- Mộtsốđặctínhnổibậtcủafrida:
Description
![Page 4: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/4.jpg)
- CàiđặtFridaCLITools:pip3installfrida-tools- CàiđặtFridaPythonbindings (Sửdụngchínhtrongbàiviết)pip3installfrida- Kiểmtralạixemfridađãcàithànhcôngchưa:
Installation->Client(máythật)
![Page 5: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/5.jpg)
Installation->Server(điệnthoạiảo)
- Tải frida-server binary từtrang releasepage,cụthểởbàinàylàfrida-server-12.1.2-android-x86.xz(Nếukhông rõthìthửhếtbinary luônarm/arm64/x86-64/x86)- frida-server versionphảiđúngvới Fridaversion.
![Page 6: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/6.jpg)
Installation- Tổngquanthìsetupnósẽnhưthếnày
Frida-client(useCLIorpythonbinding tointeractwiththeandroid)
Frida-serverListenonport27042bydefaultFrida-server
(mặcđịnhlistentrênport27042)
![Page 7: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/7.jpg)
Installation
- Kiểmtraxemsetupđúngchưa,từmáythật,gõlệnh:frida-ps -U
Thànhcông
![Page 8: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/8.jpg)
Pythonbindings
- Nhưđãnóiởtrên,chúngtasẽtậptrungvào“frida pythonbindings”.- Sửdụng fileapkgốc“InsecureBankv2”đểlàmvídụ (nhớxoácáicũđivàcàilại)
![Page 9: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/9.jpg)
Pythonbindings
- Đểsửdụng fridatrongpython, taimportnó:import frida- Bâygiờsửdụng get_usb_device() function đểlấythông tinvềdevicedevice=frida.get_usb_device()
- Rồispawnapplên:pid=device.spawn(“com.android.insecurebankv2”)device.resume(pid)
- Bâygiờchúng tađãcóđượcpidcủaappvừaspawn,attachnótạosession:session=device.attach(id)
- Giờthìinjectđoạnhook_scriptcủachúng tavàochương trìnhthôi:script=session.create_script(hook_script)script.load()
![Page 10: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/10.jpg)
Pythonbindings
- Đoạnpythoncodediễngiảiởtrên:
![Page 11: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/11.jpg)
Pythonbindings
- Tớilúcnàybạnsẽtựhỏi hook_script làcáigìđúngkhông, nólàcáclệnhchúng tacungcấpchoFridasửdụng Javascript API.Vớinó,chúng tacóthểtương táctrựctiếpvớiJavafunctionsvàobjects.
- Lưuýđoạncodechúngtacungcấpchofridasẽnằmbêntrong Java.perform(function(){ ...}),cáinàylàbắtbuộc,kiểucúphápcủaFridaJavaAPI.hook_script sẽnhưthếnày:
hook_script=“””Java.perform(function (){//dosomething});“””- Bâygiờquyếtđịnhhookcáigìnhé, trởvềcáiappnè,nhớlỗiweakcryptoởbài3không (Phân tíchtĩnh)?- Lúcđóthìcầnphảihiểucrypto,rồimôphỏng lạitrênpython, blah...blah....Lỡlúcđókhông tìmđược
key,hayđoạncryptoquávãihàthìchịuhả?- Rấtmaymắn,Fridakhông xoắnmấycáinàyJ
![Page 12: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/12.jpg)
Pythonbindings
- Chúng tatìmđượcđoạncodedecrypttrongcom/android/insecurebankv2/CryptoClass.class
- Biếtrằngnónhậnvàocrypt-text,decryptvàtrảvềplainText,khôngcầnquantâmnólàmgìbêntrong.Rấtrõràng,chỉcầngọi functionđólênsửdụngcrypt-texttamuốn làokayJ
![Page 13: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/13.jpg)
Pythonbindings
- Vậygọifunction lênbằngFridanhưnào?Chúng tasẽsửdụng Java.choose()- Tríchtừdocument fridagốc:
- Nósẽscantrênheap,tìminstancecủaclassName tamuốn, nếukhớp,onMatch callbacksẽđượcthựcthi,dựavàođótagọihàmcủainstancetìmđược.
![Page 14: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/14.jpg)
Pythonbindings- Codehiệngiờnósẽnhưthếnày:
className
Instance củaclassName tìm được trên heap
Sử dụng instance để gọifunction
![Page 15: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/15.jpg)
Pythonbindings
- Kếtquả:
- Nhưđãbiết,Dinesh@123$ làpasswordcủauserdinesh J
![Page 16: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/16.jpg)
Pythonbindings
- ThêmvàivídụnữachovuiJ- Nhớđoạndetectrootcodehông?Chúng tasẽhookvàsửanó,let’sFrida!- Đoạncodeđónằmtrongcom/android/insecurebankv2/PostLogin.class
- Nhưhình,nếudoesSuperuserApkExist(String paramString) trảvềtrue, thìrootdetected.Mặcđịnhthìchúng tađãvượtquađoạnchecknàyrồi,nhưngmàmìnhhemthích,mìnhmuốnsửanó lạiđểnódetectmìnhchovuiJ =>makeittrue!
![Page 17: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/17.jpg)
Pythonbindings
- Hàmnàytrảvềbool val,hijackgiátrịtrảvềlàxong
- Nhưnào?Lầnnàysửdụng Java.use()- Tríchtừdocument fridagốc:
![Page 18: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/18.jpg)
Pythonbindings
- Ngắngọn là Java.use()chophépchúngtaghiđè1method trongclass.- Đầutiên chọnclasscómethodđó:Java.use(‘com.android.insecurebankv2.PostLogin’)- Sauđóthìghiđèsửdụng implementation:class_PostLogin.doesSuperuserApkExist.implementation =function (){
//whatever,inthiscase,returntrue}
- Done
![Page 19: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/19.jpg)
Pythonbindings- Codenhưsau:
UseimplementationtooverridefunctiondoesSuperuserApkExist content
![Page 20: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/20.jpg)
Pythonbindings- Vàođiệnthoạiảo,đăngnhập,bịpháthiệnrootroài(>_<!)
Normalstart,bydefault Startandhooked byfridaJ
![Page 21: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/21.jpg)
Pythonbindings- Mộtvídụkhácnhé,đasốcácappđềucóclient-sidefilter,giờsửdụng fridađểbypassthửxem- Nhìnđoạncodenàytrongcom/android/insecurebankv2/ChangePassword$RequestChangePasswordTask.class:
![Page 22: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/22.jpg)
Pythonbindings- Đểýđoạnregex:((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})Đoạnnàykiểmtrađộphứctạpcủa password,nghĩalànếuchúng tađổipassworddễquáthìsẽkhông được- Mình làngườiđơngiảnnênmìnhđổithửpasswordthành“1234”:
Fail,vìpwphảitừ6->20kítự“1234”chỉcó4thôi
![Page 23: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/23.jpg)
Pythonbindings- Chúng tasẽsửdụng fridađểbypass.Lầnnàykhông injectvàoappclassnữa,vìregexmethod làtừjavapackage,
khôngphảitừcodecủadev.
from
- Hook:regex_Pattern_hook =Java.use('java.util.regex.Pattern')- Khácvớilầntrước,takhông thểxàiregex_Pattern_hook.compile.implementation bởivìtrongPatternpackagecó
nhiều loạicompilemethods (compile(String x);compile(String x,int y);etc…),dođófridasẽbịrối!- Chúng taphảinóivới frida chínhxácmethodnàođểhook,ởđâylà:compile(String x)- Sửdụngoverload:regex_Pattern_hook.compile.overload("java.lang.String").implementation
![Page 24: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/24.jpg)
Pythonbindings- Code:
Sửa regex thành “.*”,nghĩa là cho phép mọi trường hợp
![Page 25: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/25.jpg)
Pythonbindings- Trong một số trường hợp, sau khi hook app sẽ bị treo (chắc do máy ver cũ), thì reload script 1 lần
nữa là app sẽ chạy bình thường (hook đúng nha, chứ hook sai thì fail chắc rồi)- Thử nào:
![Page 26: Android Mobile Pentest 101 · Java.use(‘com.android.insecurebankv2.PostLogin’) - Sau đó thì ghi đè sử dụng implementation: class_PostLogin.doesSuperuserApkExist.implementation=](https://reader035.vdocuments.site/reader035/viewer/2022062606/5feac51905996767ea4ebcca/html5/thumbnails/26.jpg)
Pythonbindings- Đăngnhậpvàxemtronglogcatđểconfirm:
- Cònnhiều fridaapihữudụngkháckhixàivớipython: send, recv andrpcFulldocs:https://www.frida.re/docs/javascript-api/