-
Notifications
You must be signed in to change notification settings - Fork 400
/
kmainForm.py
1563 lines (1393 loc) · 64.7 KB
/
kmainForm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding=utf-8
import datetime
import re
import sys
from time import sleep
from PyQt5 import uic, QtWidgets,QtCore
from PyQt5.QtCore import Qt, QPoint, QTranslator
from PyQt5.QtGui import QStandardItemModel, QStandardItem, QCursor
from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog, QStatusBar, QLabel, QMessageBox, QHeaderView, \
QTableWidgetItem, QMenu, QAction, QActionGroup, qApp, QLineEdit
from forms import SelectPackage
from forms.AntiFrida import antiFridaForm
from forms.CallFunction import callFunctionForm
from forms.Custom import customForm
from forms.DumpAddress import dumpAddressForm
from forms.DumpSo import dumpSoForm
from forms.Fart import fartForm
from forms.FartBin import fartBinForm
from forms.JniTrace import jnitraceForm
from forms.Natives import nativesForm
from forms.Patch import patchForm
from forms.Port import portForm
from forms.SearchMemory import searchMemoryForm
from forms.SpawnAttach import spawnAttachForm
from forms.Stalker import stalkerForm
from forms.StalkerOp import stalkerMatchForm
from forms.Tuoke import tuokeForm
from forms.Wallbreaker import wallBreakerForm
from forms.Wifi import wifiForm
from forms.ZenTracer import zenTracerForm
from ui.kmain import Ui_MainWindow
from utils import LogUtil, CmdUtil, FileUtil
import json, os, threading, frida
import platform
import TraceThread
from utils.IniUtil import IniConfig
conf=IniConfig()
def restart_real_live():
qApp.exit(1207)
class kmainForm(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(kmainForm, self).__init__(parent)
self.setupUi(self)
self.initUi()
self.hooksData = {}
self.th = TraceThread.Runthread(self.hooksData, "", False,self.connType)
self.updateCmbHooks()
self.outlogger = LogUtil.Logger('all.txt', level='debug')
def initUi(self):
self.setWindowOpacity(0.93)
# 日志目录
if os.path.exists("./logs") == False:
os.makedirs("./logs")
if os.path.exists("./pcap") == False:
os.makedirs("./pcap")
# 缓存数据目录 modules classes
if os.path.exists("./tmp") == False:
os.makedirs("./tmp")
# 从手机下载dumpdex脱壳的数据
if os.path.exists("./dumpdex") == False:
os.makedirs("./dumpdex")
if os.path.exists("./fartdump") == False:
os.makedirs("./fartdump")
# 自定义脚本目录
if os.path.exists("./custom") == False:
os.makedirs("./custom")
# 保存当前hook策略的目录
if os.path.exists("./hooks") == False:
os.makedirs("./hooks")
projectPath = os.path.dirname(os.path.abspath(__file__))
if platform.system() != "Windows":
CmdUtil.execCmd("chmod 0777 " + projectPath + "/sh/linux/*")
CmdUtil.execCmd("chmod 0777 " + projectPath + "/sh/mac/*")
self.statusBar = QStatusBar()
self._translate = QtCore.QCoreApplication.translate
self.labStatus = QLabel(self._translate("kmainForm",'当前状态:未连接'))
self.setStatusBar(self.statusBar)
self.statusBar.addPermanentWidget(self.labStatus, stretch=1)
self.labPackage = QLabel('')
self.statusBar.addPermanentWidget(self.labPackage, stretch=2)
self.languageGroup = QActionGroup(self)
self.languageGroup.addAction(self.actionChina)
self.languageGroup.addAction(self.actionEnglish)
self.fridaName = conf.read("kmain", "frida_name")
self.customPort = conf.read("kmain", "usb_port")
self.address=conf.read("kmain", "wifi_addr")
self.wifi_port = conf.read("kmain", "wifi_port")
language = conf.read("kmain", "language")
if language == "China":
self.actionChina.setChecked(True)
else:
self.actionEnglish.setChecked(True)
if self.actionChina.isChecked():
typePath="./config/type.json"
else:
typePath = "./config/type_en.json"
with open(typePath, "r", encoding="utf8") as typeFile:
self.typeData = json.loads(typeFile.read())
self.actionAttach.triggered.connect(self.actionAttachStart)
self.actionSpawn.triggered.connect(self.actionSpawnStart)
self.actionAttachName.triggered.connect(self.actionAttachNameStart)
self.actionabort.triggered.connect(self.actionAbort)
self.actionStop.setEnabled(False)
self.actionStop.triggered.connect(self.StopAttach)
self.actionClearTmp.triggered.connect(self.ClearTmp)
self.actionClearLogs.triggered.connect(self.ClearLogs)
self.actionClearOutlog.triggered.connect(self.ClearOutlog)
self.actionPushFartSo.triggered.connect(self.PushFartSo)
self.actionClearHookJson.triggered.connect(self.ClearHookJson)
self.actionPullDumpDexRes.triggered.connect(self.PullDumpDex)
self.actionPushFridaServer.triggered.connect(self.PushFridaServer)
self.actionPushFridaServerX86.triggered.connect(self.PushFridaServerX86)
self.actionPullFartRes.triggered.connect(self.PullFartRes)
self.actionFrida32Start.triggered.connect(self.Frida32Start)
self.actionFrida64Start.triggered.connect(self.Frida64Start)
self.actionSuC.triggered.connect(self.ChangeSuC)
self.actionSu0.triggered.connect(self.ChangeSu0)
self.actionMks0.triggered.connect(self.ChangeMks0)
self.adbHeadGroup = QActionGroup(self)
self.adbHeadGroup.addAction(self.actionMks0)
self.adbHeadGroup.addAction(self.actionSuC)
self.adbHeadGroup.addAction(self.actionSu0)
self.actionFridax86Start.triggered.connect(self.FridaX86Start)
self.actionFridax64Start.triggered.connect(self.FridaX64Start)
self.actionPullApk.triggered.connect(self.PullApk)
self.connectHeadGroup = QActionGroup(self)
self.connectHeadGroup.addAction(self.actionWifi)
self.connectHeadGroup.addAction(self.actionUsb)
self.actionWifi.triggered.connect(self.WifiConn)
self.actionUsb.triggered.connect(self.UsbConn)
self.actionVer14.triggered.connect(self.ChangeVer14)
self.actionVer15.triggered.connect(self.ChangeVer15)
self.actionVer16.triggered.connect(self.ChangeVer16)
self.actionEnglish.triggered.connect(self.ChangeEnglish)
self.actionChina.triggered.connect(self.ChangeChina)
self.actionChangePort.triggered.connect(self.ChangePort)
self.verGroup = QActionGroup(self)
self.verGroup.addAction(self.actionVer14)
self.verGroup.addAction(self.actionVer15)
self.verGroup.addAction(self.actionVer16)
self.btnDumpPtr.clicked.connect(self.dumpPtr)
self.btnDumpSo.clicked.connect(self.dumpSo)
self.btnFart.clicked.connect(self.dumpFart)
self.btnDumpDex.clicked.connect(self.dumpDex)
self.btnWallbreaker.clicked.connect(self.wallBreaker)
self.btnCallFunction.clicked.connect(self.callFunction)
self.chkNetwork.toggled.connect(self.hookNetwork)
self.chkJni.toggled.connect(self.hookJNI)
self.chkJavaEnc.toggled.connect(self.hookJavaEnc)
self.chkHookEvent.toggled.connect(self.hookEvent)
self.chkRegisterNative.toggled.connect(self.hookRegisterNative)
self.chkArtMethod.toggled.connect(self.hookArtMethod)
self.chkLibArt.toggled.connect(self.hookLibArm)
self.chkSslPining.toggled.connect(self.hookSslPining)
self.chkAntiDebug.toggled.connect(self.hookAntiDebug)
self.chkNewJnitrace.toggled.connect(self.hookNewJnitrace)
self.btnMatchMethod.clicked.connect(self.matchMethod)
self.btnNatives.clicked.connect(self.hookNatives)
self.btnStalker.clicked.connect(self.stalker)
self.btnCustom.clicked.connect(self.custom)
self.btnTuoke.clicked.connect(self.tuoke)
self.btnPatch.clicked.connect(self.patch)
self.txtModule.textChanged.connect(self.changeModule)
self.txtClass.textChanged.connect(self.changeClass)
self.txtSymbol.textChanged.connect(self.changeSymbol)
self.txtMethod.textChanged.connect(self.changeMethod)
self.btnSaveHooks.clicked.connect(self.saveHooks)
self.btnImportHooks.clicked.connect(self.importHooks)
self.btnLoadHooks.clicked.connect(self.loadHooks)
self.btnClearHooks.clicked.connect(self.clearHooks)
if self.actionChina.isChecked():
self.header = ["名称", "类名/模块名", "函数", "备注"]
else:
self.header = ["name", "class or func", "func", "bak"]
self.tabHooks.setColumnCount(4)
self.tabHooks.setHorizontalHeaderLabels(self.header)
self.tabHooks.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.tabHooks.setContextMenuPolicy(Qt.CustomContextMenu)
self.tabHooks.customContextMenuRequested[QPoint].connect(self.rightMenuShow)
self.btnMethod.clicked.connect(self.searchMethod)
self.btnExport.clicked.connect(self.searchExport)
self.btnSymbol.clicked.connect(self.searchSymbol)
self.btnSymbolClear.clicked.connect(self.clearSymbol)
self.btnMethodClear.clicked.connect(self.clearMethod)
self.txtMethod.textChanged.connect(self.changeMethod)
self.txtSymbol.textChanged.connect(self.changeSymbol)
self.btnFlush.clicked.connect(self.appInfoFlush)
self.btnFartOpBin.clicked.connect(self.fartOpBin)
self.btnOpStalkerLog.clicked.connect(self.stalkerOpLog)
# self.btnOpFartLog.clicked.connect(self.fartOpLog)
self.btnMemSearch.clicked.connect(self.searchMem)
self.btnAntiFrida.clicked.connect(self.antiFrida)
self.dumpForm = dumpAddressForm()
self.jniform = jnitraceForm()
self.newJniform=jnitraceForm()
self.zenTracerForm = zenTracerForm()
self.nativesForm = nativesForm()
self.spawnAttachForm = spawnAttachForm()
self.stalkerForm = stalkerForm()
self.pform = patchForm()
self.dumpSoForm = dumpSoForm()
self.fartForm = fartForm()
self.wallBreakerForm = wallBreakerForm()
self.customForm = customForm()
self.callFunctionForm = callFunctionForm()
self.fartBinForm = fartBinForm()
self.stalkerMatchForm = stalkerMatchForm()
self.wifiForm=wifiForm()
self.portForm = portForm()
self.searchMemForm= searchMemoryForm()
self.antiFdForm=antiFridaForm()
self.modules = None
self.classes = None
self.symbols = None
self.methods = None
self.chkNetwork.tag = "r0capture"
self.chkJni.tag = "jnitrace"
self.chkJavaEnc.tag = "javaEnc"
self.chkSslPining.tag = "sslpining"
self.chkRegisterNative.tag = "RegisterNative"
self.chkArtMethod.tag = "ArtMethod"
self.chkLibArt.tag = "libArt"
self.chkHookEvent.tag = "hookEvent"
self.connType="usb"
self.actionattach = QtWidgets.QAction(self)
self.actionattach.setText("attach")
self.actionattach.setToolTip("attach by packageName")
self.actionattach.triggered.connect(self.actionAttachNameStart)
self.toolBar.addAction(self.actionattach)
self.actionattachF = QtWidgets.QAction(self)
self.actionattachF.setText("attachF")
self.actionattachF.setToolTip("attach current top app")
self.actionattachF.triggered.connect(self.actionAttachStart)
self.toolBar.addAction(self.actionattachF)
self.actionspawn = QtWidgets.QAction(self)
self.actionspawn.setText("spawn")
self.actionspawn.triggered.connect(self.actionSpawnStart)
self.toolBar.addAction(self.actionspawn)
self.actionstop = QtWidgets.QAction(self)
self.actionstop.setText("stop")
self.actionstop.triggered.connect(self.StopAttach)
self.toolBar.addAction(self.actionstop)
self.curFridaVer = "14.2.18"
self.actionVer14.setChecked(True)
# 16.0.8 15.1.9 14.2.18
# res=CmdUtil.execCmdData("frida --version")
# if "15." in res:
# self.curFridaVer = "15.1.9"
# self.actionVer15.setChecked(True)
# elif "14." in res:
# self.curFridaVer = "14.2.18"
# self.actionVer14.setChecked(True)
# elif "16." in res:
# self.curFridaVer = "16.0.8"
# self.actionVer16.setChecked(True)
# else:
# self.curFridaVer = "15.1.9"
# self.actionVer15.setChecked(True)
def clearSymbol(self):
self.listSymbol.clear()
def clearMethod(self):
self.listMethod.clear()
def changeMethod(self, data):
self.listMethod.clear()
if len(data) > 0:
for item in self.methods:
if data in item:
self.listMethod.addItem(item)
else:
for item in self.methods:
self.listMethod.addItem(item)
def changeSymbol(self, data):
self.listSymbol.clear()
if len(data) > 0:
for item in self.symbols:
if data in item["name"]:
self.listSymbol.addItem(item["name"])
else:
for item in self.symbols:
self.listSymbol.addItem(item["name"])
def searchExport(self):
if len(self.txtModule.text()) <= 0:
QMessageBox().information(self, "hint", self._translate("kmainForm","未填写模块名称"))
return
appinfo = self.th.default_api.searchinfo("export", self.txtModule.text().split("----")[0])
self.searchAppInfoRes(appinfo)
def searchSymbol(self):
if len(self.txtModule.text()) <= 0:
QMessageBox().information(self, "hint", self._translate("kmainForm","未填写模块名称"))
return
appinfo=self.th.default_api.searchinfo("symbol", self.txtModule.text().split("----")[0])
self.searchAppInfoRes(appinfo)
def searchMethod(self):
if len(self.txtClass.text()) <= 0:
QMessageBox().information(self, "hint",self._translate("kmainForm","未填写类型名称"))
return
appinfo=self.th.default_api.searchinfo("method", self.txtClass.text())
self.searchAppInfoRes(appinfo)
def hooksRemove(self):
for item in self.tabHooks.selectedItems():
# 因为patch是多个的。所以移除的时候要注意。不然会全部移掉的。
if self.tabHooks.item(item.row(), 0).text() == "patch":
removeItemData = self.tabHooks.item(item.row(), 1).text() + self.tabHooks.item(item.row(), 2).text()
for idx in range(len(self.hooksData["patch"])):
hookItem = self.hooksData["patch"][idx]
if hookItem["class"] + hookItem["method"] == removeItemData:
self.hooksData["patch"].pop(idx)
else:
self.hooksData.pop(self.tabHooks.item(item.row(), 0).text())
self.updateTabHooks()
self.refreshChecks()
# 右键菜单
def rightMenuShow(self):
rightMenu = QMenu(self.tabHooks)
removeAction = QAction(self._translate("kmainForm","删除"), self, triggered=self.hooksRemove)
rightMenu.addAction(removeAction)
rightMenu.exec_(QCursor.pos())
# 打印操作日志
def log(self, logstr):
datestr = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S ')
self.txtLogs.appendPlainText(datestr + logstr)
# 打印输出日志
def outlog(self, logstr):
if self.actionConsoleLog.isChecked()==False:
datestr = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S ')
self.txtoutLogs.appendPlainText(datestr + logstr)
self.outlogger.logger.debug(logstr)
if "default.js init hook success" in logstr:
QMessageBox().information(self, "hint", self._translate("kmainForm","附加进程成功"))
# 线程调用脚本结束,并且触发结束信号
def StopAttach(self):
self.th.quit()
def ClearTmp(self):
path = "./tmp/"
ls = os.listdir(path)
for i in ls:
c_path = os.path.join(path, i)
os.remove(c_path)
def ClearLogs(self):
path = "./logs/"
ls = os.listdir(path)
for i in ls:
c_path = os.path.join(path, i)
try:
os.remove(c_path)
except:
pass
def ClearOutlog(self):
self.txtoutLogs.setPlainText("")
def PushFartSo(self):
# 有些手机是用su 0来执行shell命令的。不太懂怎么判断是哪种。
res = CmdUtil.adbshellCmd("mkdir /data/local/tmp/fart")
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "操作失败.") + res)
return
res = CmdUtil.adbshellCmd("chmod 0777 /data/local/tmp/fart")
self.log(res)
if "invalid" in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "设置权限失败。可能是su权限错误,请先cmd切换"))
return
res = CmdUtil.adbshellCmd("mkdir /sdcard/fart")
self.log(res)
res = CmdUtil.adbshellCmd("chmod 0777 /sdcard/fart")
self.log(res)
res = CmdUtil.execCmd("adb push ./lib/fart.so /data/local/tmp/fart/fart.so")
self.log(res)
if "file pushed" not in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "上传失败,可能未连接设备.")+res)
return
res = CmdUtil.execCmd("adb push ./exec/r0gson.dex /data/local/tmp/r0gson.dex")
self.log(res)
res = CmdUtil.adbshellCmd("chmod 0777 /data/local/tmp/gson.jar")
self.log(res)
res = CmdUtil.execCmd("adb push ./lib/fart64.so /data/local/tmp/fart/fart64.so")
self.log(res)
res = CmdUtil.adbshellCmd("chmod 0777 /data/local/tmp/fart/fart.so")
self.log(res)
res = CmdUtil.adbshellCmd("chmod 0777 /data/local/tmp/fart/fart64.so")
self.log(res)
# 因为好像有些手机不能直接push到/data/app目录。所以先放tmp再拷贝过去
res = CmdUtil.adbshellCmd("cp /data/local/tmp/fart/fart.so /data/app/")
self.log(res)
res = CmdUtil.adbshellCmd("cp /data/local/tmp/fart/fart64.so /data/app/")
self.log(res)
QMessageBox().information(self, "hint", self._translate("kmainForm","上传完成"))
def PullDumpDex(self):
cmd = ""
if len(self.th.attachName) > 0:
pname = self.th.attachName
else:
self.spawnAttachForm.flushList()
res = self.spawnAttachForm.exec()
if res == 0:
return
pname = self.spawnAttachForm.packageName
cmd = "adb pull /data/data/%s/files/dump_dex_%s ./dumpdex/%s/" % (pname, pname, pname)
res = CmdUtil.execCmd(cmd)
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint", self._translate("kmainForm","下载失败.") + res)
return
if "not found" in res:
QMessageBox().information(self, "hint",self._translate("kmainForm","下载失败.没有连接设备") )
return
QMessageBox().information(self, "hint", self._translate("kmainForm","下载完成") )
def PushFridaServerNormal(self,arch):
try:
name32=""
name64=""
if self.fridaName!="":
name32=self.fridaName+"32"
name64=self.fridaName+"64"
if arch=="arm":
arch32="arm"
arch64="arm64"
elif arch=="x86":
arch32="x86"
arch64="x86_64"
res = CmdUtil.execCmd(f"adb push ./exec/frida-server-{self.curFridaVer}-android-{arch32} /data/local/tmp/"+name32)
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "上传失败.") + res)
return
res = CmdUtil.execCmd(f"adb push ./exec/frida-server-{self.curFridaVer}-android-{arch64} /data/local/tmp/"+name64)
self.log(res)
if "file pushed" not in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "上传失败,可能未连接设备.") + res)
return
if self.fridaName!="":
res = CmdUtil.adbshellCmd("chmod 0777 /data/local/tmp/"+self.fridaName+"*")
else:
res = CmdUtil.adbshellCmd("chmod 0777 /data/local/tmp/frida*")
self.log(res)
if "invalid" in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "上传完成,但是设置权限失败。可能是su权限错误,请先cmd切换."))
else:
QMessageBox().information(self, "hint", self._translate("kmainForm", "上传完成."))
except Exception as ex:
QMessageBox().information(self, "hint", self._translate("kmainForm", "上传异常.") + str(ex))
def PushFridaServer(self):
self.PushFridaServerNormal("arm")
def PushFridaServerX86(self):
self.PushFridaServerNormal("x86")
def PullFartRes(self):
cmd = ""
if len(self.th.attachName) > 0:
pname = self.th.attachName
else:
self.spawnAttachForm.flushList()
res = self.spawnAttachForm.exec()
if res == 0:
return
pname = self.spawnAttachForm.packageName
cmd = "rm /sdcard/fart -rf"
res = CmdUtil.adbshellCmd(cmd)
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint", res)
return
cmd = "mkdir -p /sdcard/fart/%s " % pname
res = CmdUtil.adbshellCmd(cmd)
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint", res)
return
cmd = "cp /data/data/%s/fart/ /sdcard/fart/%s/ -rf" % (pname, pname)
res = CmdUtil.adbshellCmd(cmd)
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint", res)
return
cmd = "adb pull /sdcard/fart/%s/ ./fartdump/%s/" % (pname, pname)
res = CmdUtil.execCmd(cmd)
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint", res)
return
if "not found" in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "下载失败.没有连接设备") )
return
QMessageBox().information(self, "hint", self._translate("kmainForm", "下载完成.输出结果在目录./fartdump/%s/") % pname)
def PullApk(self):
cmdtp = "grep"
if platform.system() == "Windows":
cmdtp = "findstr"
cmd = "adb shell dumpsys window | %s mCurrentFocus" % cmdtp
res = CmdUtil.execCmd(cmd)
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint", res)
return
lines=res.split("\n")
for tmpline in lines:
if len(tmpline)>0:
line=tmpline
line = re.split(r"[ /]", res)
if len(line) < 5:
QMessageBox().information(self, "hint", self._translate("kmainForm", "匹配失败,") + res)
return
packageName = line[4]
if "StatusBar" in packageName:
QMessageBox().information(self, "hint",self._translate("kmainForm", "匹配失败,手机可能锁屏中,请解锁"))
return
cmd = "adb shell dumpsys activity -p %s|%s baseDir" % (packageName, cmdtp)
res = CmdUtil.execCmd(cmd)
self.log(res)
if "baseDir" not in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "匹配失败,可能未连接手机"))
return
lines = res.split("\n")
for tmpline in lines:
if packageName in tmpline:
line = tmpline
pathRes= CmdUtil.execCmdData("adb shell pm path %s" % packageName)
pathRes=pathRes.replace("package:","")
if os.path.exists("./apks") == False:
os.makedirs("./apks")
for path in pathRes.split("\n"):
if "apk" not in path:
continue
cmd = "adb pull %s ./apks/%s.apk" % (path, packageName)
res = CmdUtil.execCmd(cmd)
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint", res)
else:
QMessageBox().information(self, "hint", packageName +self._translate("kmainForm", ".apk下载成功.输出结果在目录./apks/"))
def ReplaceSh(self,rfile,wfile,name):
data = FileUtil.readFile(rfile)
adb = "adb"
if platform.system() == "Darwin":
adb = "%adb%"
if self.connType == "wifi":
data = data.replace("%fridaName%", name + " -l 0.0.0.0:" + self.wifi_port)
data=data.replace("%customPort%",f"{adb} forward tcp:{self.wifi_port} tcp:{self.wifi_port}")
elif self.connType == "usb":
if self.customPort!=None and len(self.customPort)>0:
data = data.replace("%fridaName%", name + " -l 0.0.0.0:" + self.customPort)
data=data.replace("%customPort%",f"{adb} forward tcp:{self.customPort} tcp:{self.customPort}")
else:
data = data.replace("%fridaName%", name)
data = data.replace("%customPort%","")
if self.actionSu0.isChecked():
data = data.replace("%sumod%", "su 0")
elif self.actionSuC.isChecked():
data = data.replace("%sumod%", "su -c")
elif self.actionMks0.isChecked():
data = data.replace("%sumod%", "mks 0")
if platform.system()=="Darwin":
adbPath= CmdUtil.execCmdData("which adb")
if adbPath=="":
adbPath="adb"
data=data.replace("%adb%",adbPath.replace("\n",""))
if self.fridaName != None and len(self.fridaName) > 0:
data = data.replace("%fName%", self.fridaName)
FileUtil.writeFile(wfile,data)
def ShStart(self, name):
projectPath = os.path.abspath("./")
if platform.system() == "Windows":
shfile = "%s\\sh\\tmp\\frida_win.tmp"% (projectPath)
savefile="%s\\sh\\tmp\\frida_win.bat"% (projectPath)
self.ReplaceSh(shfile,savefile,name)
cmd = r"start " + savefile
elif platform.system() == 'Linux':
shfile = "%s/sh/tmp/frida_linux.tmp"% (projectPath)
savefile = "%s/sh/tmp/frida_linux.sh" % (projectPath)
self.ReplaceSh(shfile, savefile, name)
CmdUtil.execCmd("chmod 0777 " + projectPath + "/sh/tmp/*")
cmd = "gnome-terminal -e 'bash -c \"%s; exec bash\"'" % savefile
else:
shfile = "%s/sh/tmp/frida_mac.tmp"% (projectPath)
savefile = "%s/sh/tmp/frida_mac.sh" % (projectPath)
self.ReplaceSh(shfile, savefile, name)
CmdUtil.execCmd("chmod 0777 " + projectPath + "/sh/tmp/*")
cmd = "bash -c " + savefile
os.system(cmd)
def ChangeVer14(self, checked):
if checked==False:
return
self.curFridaVer="14.2.18"
def ChangeVer15(self, checked):
if checked==False:
return
self.curFridaVer = "15.1.9"
def ChangeVer16(self, checked):
if checked==False:
return
self.curFridaVer = "16.0.8"
def ChangeEnglish(self,checked):
if checked==False:
return
conf.write("kmain","language","English")
reply = QMessageBox.question(self,
"hint",
self._translate("kmainForm","是否立刻重启应用生效?"),
QMessageBox.Yes | QMessageBox.No)
if reply:
restart_real_live()
def ChangeChina(self,checked):
if checked==False:
return
conf.write("kmain", "language", "China")
reply = QMessageBox.question(self,
"hint",
self._translate("kmainForm", "是否立刻重启应用生效?"),
QMessageBox.Yes | QMessageBox.No)
if reply:
restart_real_live()
def Frida32Start(self):
if self.fridaName !=None and len(self.fridaName)>0:
name=self.fridaName+"32"
else:
name=f"frida-server-{self.curFridaVer}-android-arm"
self.ShStart(name)
def Frida64Start(self):
if self.fridaName !=None and len(self.fridaName)>0:
name=self.fridaName+"64"
else:
name=f"frida-server-{self.curFridaVer}-android-arm64"
self.ShStart(name)
def FridaX86Start(self):
if self.fridaName !=None and len(self.fridaName)>0:
name=self.fridaName+"32"
else:
name=f"frida-server-{self.curFridaVer}-android-x86"
self.ShStart(name)
def FridaX64Start(self):
if self.fridaName !=None and len(self.fridaName)>0:
name=self.fridaName+"64"
else:
name=f"frida-server-{self.curFridaVer}-android-x86_64"
self.ShStart(name)
def changeCmdType(self,data):
CmdUtil.cmdhead = data
def ChangeSuC(self, checked):
if checked==False:
return
self.changeCmdType(self.actionSuC.text())
def ChangeSu0(self, checked):
if checked==False:
return
self.changeCmdType(self.actionSu0.text())
def ChangeMks0(self,checked):
if checked==False:
return
self.changeCmdType(self.actionMks0.text())
def ClearHookJson(self):
path = "./hooks/"
ls = os.listdir(path)
for i in ls:
c_path = os.path.join(path, i)
try:
os.remove(c_path)
except:
pass
self.updateCmbHooks()
# 进程结束时的状态切换,和打印e
def taskOver(self):
self.log("附加进程结束")
self.changeAttachStatus(False)
QMessageBox().information(self, "hint",self._translate("kmainForm","成功停止附加进程") )
# 这是附加结束时的状态栏显示包名
def attachOver(self, name):
if "ERROR" in name:
QMessageBox().information(self, "hint",self._translate("kmainForm","附加失败.")+name)
self.changeAttachStatus(False)
return
tmppath = "./tmp/spawnPackage.txt"
mode = "r+"
if os.path.exists(tmppath) == False:
mode = "w+"
with open(tmppath, mode) as packageFile:
packageData = packageFile.read()
fsize = packageFile.tell()
packageFile.seek(fsize)
if name not in packageData:
packageFile.write(name + "\n")
self.labPackage.setText(name)
# appinfo=self.th.default_api.loadappinfo()
# self.loadAppInfo(appinfo)
def getFridaDevice(self):
if self.connType=="usb":
if self.customPort != None and len(self.customPort) > 0:
str_host = "127.0.0.1:%s" % (self.customPort)
manager = frida.get_device_manager()
device = manager.add_remote_device(str_host)
return device
else:
return frida.get_usb_device()
elif self.connType=="wifi":
str_host = "%s:%s" % (self.address, self.wifi_port)
manager = frida.get_device_manager()
device = manager.add_remote_device(str_host)
return device
# 启动附加
def actionAttachStart(self):
self.log("actionAttach")
try:
if self.connType=="wifi":
if len(self.address)<8 or len(self.wifi_port)<0:
QMessageBox().information(self, "hint", self._translate("kmainForm","当前为wifi连接,但是未设置地址或端口"))
return
# 查下进程。能查到说明frida_server开启了
device = self.getFridaDevice()
device.enumerate_processes()
self.changeAttachStatus(True)
self.th = TraceThread.Runthread(self.hooksData, "", False,self.connType)
self.th.address=self.address
self.th.port=self.wifi_port
self.th.customPort=self.customPort
self.th.taskOverSignel.connect(self.taskOver)
self.th.loggerSignel.connect(self.log)
self.th.outloggerSignel.connect(self.outlog)
self.th.loadAppInfoSignel.connect(self.loadAppInfo)
self.th.attachOverSignel.connect(self.attachOver)
self.th.searchAppInfoSignel.connect(self.searchAppInfoRes)
self.th.searchMemorySignel.connect(self.searchMemResp)
self.th.setBreakSignel.connect(self.setBreakResp)
self.th.attachType="attachCurrent"
self.th.start()
if len(self.hooksData) <= 0:
# QMessageBox().information(self, "提示", "未设置hook选项")
self.log(self._translate("kmainForm","未设置hook选项"))
except Exception as ex:
self.log(self._translate("kmainForm","附加异常")+".err:" + str(ex))
QMessageBox().information(self, "hint", self._translate("kmainForm","附加异常")+"." + str(ex))
# spawn的方式附加进程
def actionSpawnStart(self):
self.log("actionSpawnStart")
self.spawnAttachForm.flushList()
res = self.spawnAttachForm.exec()
if res == 0:
return
try:
if self.connType=="wifi" and (len(self.address)<8 or len(self.wifi_port)<=0):
QMessageBox().information(self, "hint",self._translate("kmainForm","当前为wifi连接,但是未设置地址或端口"))
return
# 查下进程。能查到说明frida_server开启了
device = self.getFridaDevice()
device.enumerate_processes()
self.changeAttachStatus(True)
self.th = TraceThread.Runthread(self.hooksData, self.spawnAttachForm.packageName, True,self.connType)
self.th.address=self.address
self.th.port=self.wifi_port
self.th.customPort = self.customPort
self.th.taskOverSignel.connect(self.taskOver)
self.th.loggerSignel.connect(self.log)
self.th.outloggerSignel.connect(self.outlog)
self.th.loadAppInfoSignel.connect(self.loadAppInfo)
self.th.attachOverSignel.connect(self.attachOver)
self.th.searchAppInfoSignel.connect(self.searchAppInfoRes)
self.th.searchMemorySignel.connect(self.searchMemResp)
self.th.attachType="spawn"
self.th.start()
if len(self.hooksData) <= 0:
# QMessageBox().information(self, "提示", "未设置hook选项")
self.log(self._translate("kmainForm","未设置hook选项"))
except Exception as ex:
self.log(self._translate("kmainForm","附加异常")+".err:" + str(ex))
QMessageBox().information(self, "hint", self._translate("kmainForm","附加异常.") + str(ex))
# 修改ui的状态表现
def changeAttachStatus(self, isattach):
if isattach:
self.menuAttach.setEnabled(False)
self.actionStop.setEnabled(True)
self.labStatus.setText( self._translate("kmainForm","当前状态:已连接") )
else:
self.menuAttach.setEnabled(True)
self.actionStop.setEnabled(False)
self.labStatus.setText(self._translate("kmainForm","当前状态:未连接") )
self.labPackage.setText("")
# 根据进程名进行附加进程
def actionAttachNameStart(self):
self.log("actionAttachName")
try:
if self.connType=="wifi" and (len(self.address)<8 or len(self.wifi_port)):
QMessageBox().information(self, "hint", self._translate("kmainForm","当前为wifi连接,但是未设置地址或端口"))
return
device = self.getFridaDevice()
process = device.enumerate_processes()
selectPackageForm = SelectPackage.selectPackageForm()
selectPackageForm.setPackages(process)
res = selectPackageForm.exec()
if res == 0:
return
self.changeAttachStatus(True)
self.th = TraceThread.Runthread(self.hooksData, selectPackageForm.packageName, False,self.connType)
self.th.address=self.address
self.th.port=self.wifi_port
self.th.taskOverSignel.connect(self.taskOver)
self.th.loggerSignel.connect(self.log)
self.th.outloggerSignel.connect(self.outlog)
self.th.loadAppInfoSignel.connect(self.loadAppInfo)
self.th.attachOverSignel.connect(self.attachOver)
self.th.searchAppInfoSignel.connect(self.searchAppInfoRes)
self.th.searchMemorySignel.connect(self.searchMemResp)
self.th.attachType = "attach"
self.th.start()
except Exception as ex:
self.log(self._translate("kmainForm","附加异常")+".err:" + str(ex))
QMessageBox().information(self, "hint", self._translate("kmainForm","附加异常.") + str(ex))
def ChangePort(self):
self.portForm.txtFridaName.setText(self.fridaName)
self.portForm.txtPort.setText(self.customPort)
res=self.portForm.exec()
if res==0:
return
self.fridaName = self.portForm.fridaName
self.customPort = self.portForm.port
conf.write("kmain", "frida_name", self.fridaName)
conf.write("kmain", "usb_port", self.customPort)
def WifiConn(self):
self.wifiForm.txtAddress.setText(self.address)
self.wifiForm.txtPort.setText(self.wifi_port)
res=self.wifiForm.exec()
if res==0 :
return
self.connType="wifi"
self.address=self.wifiForm.address
self.wifi_port=self.wifiForm.port
conf.write("kmain", "wifi_addr", self.address)
conf.write("kmain", "wifi_port", self.wifi_port)
def UsbConn(self):
self.connType="usb"
self.actionUsb.setChecked(True)
self.actionWifi.setChecked(False)
# 是否附加进程了
def isattach(self):
if "未连接" in self.labStatus.text():
self.log(self._translate("kmainForm", "Error:还未附加进程"))
QMessageBox().information(self, "hint", self._translate("kmainForm", "Error:未附加进程"))
return False
return True
# ====================start======需要附加后才能使用的功能,基本都是在内存中查数据================================
def dumpPtr(self):
if self.isattach() == False:
return
if self.modules == None or len(self.modules) <= 0:
self.log(self._translate("kmainForm", "Error:未附加进程或操作太快,请稍等"))
QMessageBox().information(self, "hint", self._translate("kmainForm","Error:未附加进程或操作太快,请稍等"))
return
mods = []
for item in self.modules:
mods.append(item["name"])
self.log(self._translate("kmainForm","dump指定地址"))
self.dumpForm.modules = mods
self.dumpForm.initData()
res = self.dumpForm.exec()
if res == 0:
return
# 设置了module就会以module为基址再加上address去dump。如果不设置module。就会直接dump指定的address
self.th.default_api.dumpptr(self.dumpForm.moduleName,self.dumpForm.address, self.dumpForm.dumpType,self.dumpForm.size)
def dumpSo(self):
if self.isattach() == False:
return
if self.modules == None or len(self.modules) <= 0:
self.log(self._translate("kmainForm","Error:未附加进程或操作太快,请稍等"))
QMessageBox().information(self, "hint",self._translate("kmainForm", "Error:未附加进程或操作太快,请稍等"))
return
mods = []
for item in self.modules:
mods.append(item["name"])
self.log("dump so")
self.dumpSoForm.modules = mods
self.dumpSoForm.initData()
res = self.dumpSoForm.exec()
if res == 0:
return
soName=self.dumpSoForm.moduleName
module_info = self.th.default_api.findmodule(soName)
print(module_info)
base = module_info["base"]
size = module_info["size"]
module_buffer = self.th.default_api.dumpmodule(soName)
if module_buffer != -1:
dump_so_name = soName + ".dump.so"
with open(dump_so_name, "wb") as f:
f.write(module_buffer)
f.close()
arch = self.th.default_api.arch()
fix_so_name = CmdUtil.fix_so(arch, soName, dump_so_name, base, size)
self.outlog(fix_so_name)
os.remove(dump_so_name)
QMessageBox().information(self, "hint",self._translate("kmainForm", f"dump {soName} 成功"))
def dumpFart(self):
if self.isattach() == False:
return
if "tuoke" not in self.hooksData:
self.log(self._translate("kmainForm", "Error:未勾选脱壳脚本"))
QMessageBox().information(self, "hint",self._translate("kmainForm", "Error:未勾选脱壳脚本"))
return
if self.hooksData["tuoke"]["class"] != "fart":