Skip to content

Commit 8945d05

Browse files
authored
Add Quark Script APIs to detect hard-coded credentials (#372)
1 parent 892a5cd commit 8945d05

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

quark/script/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ def hasUrl(self) -> List[str]:
129129
"""
130130
return self.hasString(URL_REGEX, True)
131131

132+
def getParamValues(self) -> List[str]:
133+
"""Get parameter values from behavior.
134+
135+
:return: python list containing parameter values
136+
"""
137+
allResult = self.hasString(".*", True)
138+
139+
paramValues = []
140+
for result in allResult:
141+
if result[0] == "(" and result[-1] == ")" and \
142+
self.firstAPI.innerObj.class_name in result and \
143+
self.secondAPI.innerObj.class_name in result:
144+
145+
paramValues = result[1:-1].split(",")[1:]
146+
147+
return paramValues
148+
132149

133150
class QuarkResult:
134151
def __init__(self, quark: Quark, ruleInstance: Rule) -> None:
@@ -192,6 +209,15 @@ def _wrapMethodObjectWithoutCache(self, methodObj: MethodObject) -> Method:
192209
else:
193210
return None
194211

212+
def getAllStrings(self) -> List[str]:
213+
"""
214+
List all strings inside the target APK.
215+
216+
:return: python list containing all defined strings.
217+
"""
218+
apkinfo = self.quark.apkinfo
219+
return apkinfo.get_strings()
220+
195221

196222
def runQuarkAnalysis(samplePath: PathLike, ruleInstance: Rule) -> QuarkResult:
197223
"""Given detection rule and target sample, this instance runs the basic

tests/script/test_script.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ def testHasUrl(QUARK_ANALYSIS_RESULT):
170170

171171
assert "www.baidu.com" in result
172172

173+
@staticmethod
174+
def testGetParamValues(QUARK_ANALYSIS_RESULT):
175+
behaviorOccurList = QUARK_ANALYSIS_RESULT.behaviorOccurList
176+
behavior = next(
177+
filter(
178+
lambda b: "checkWifiCanOrNotConnectServer"
179+
in b.methodCaller.fullName,
180+
behaviorOccurList,
181+
)
182+
)
183+
184+
assert behavior.getParamValues()[0] == "ping www.baidu.com"
185+
173186

174187
class TestQuarkReuslt:
175188
@staticmethod
@@ -213,6 +226,10 @@ def testMethodGetXrefFrom(QUARK_ANALYSIS_RESULT):
213226

214227
assert expectedMethod in caller_list
215228

229+
@staticmethod
230+
def testgetAllStrings(QUARK_ANALYSIS_RESULT):
231+
assert len(QUARK_ANALYSIS_RESULT.getAllStrings()) == 1005
232+
216233

217234
def testRunQuarkAnalysis(SAMPLE_PATH):
218235
ruleset = Ruleset(RULE_FOLDER_PATH)

0 commit comments

Comments
 (0)