Refactor Android modules to remove duplication (#368)

* Remove duplicated detection logic from GetProp modules
* Deduplicate settings and processes
* Refactor detection in artifacts
* Improves Artifact class
---------

Co-authored-by: tek <tek@randhome.io>
This commit is contained in:
Donncha Ó Cearbhaill
2023-07-26 13:42:17 +02:00
committed by GitHub
parent 1d740ad802
commit 57d4aca72e
21 changed files with 390 additions and 302 deletions
+41
View File
@@ -0,0 +1,41 @@
# Mobile Verification Toolkit (MVT)
# Copyright (c) 2021-2023 Claudio Guarnieri.
# Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/
import logging
from mvt.android.artifacts.getprop import GetProp
from mvt.common.indicators import Indicators
from ..utils import get_artifact
class TestGetPropArtifact:
def test_parsing(self):
gp = GetProp()
file = get_artifact("android_data/getprop.txt")
with open(file) as f:
data = f.read()
assert len(gp.results) == 0
gp.parse(data)
assert len(gp.results) == 13
assert gp.results[0]["name"] == "af.fast_track_multiplier"
assert gp.results[0]["value"] == "1"
def test_ioc_check(self, indicator_file):
gp = GetProp()
file = get_artifact("android_data/getprop.txt")
with open(file) as f:
data = f.read()
gp.parse(data)
ind = Indicators(log=logging.getLogger())
ind.parse_stix2(indicator_file)
ind.ioc_collections[0]["android_property_names"].append(
"dalvik.vm.appimageformat"
)
gp.indicators = ind
assert len(gp.detected) == 0
gp.check_indicators()
assert len(gp.detected) == 1
+38
View File
@@ -0,0 +1,38 @@
# Mobile Verification Toolkit (MVT)
# Copyright (c) 2021-2023 Claudio Guarnieri.
# Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/
import logging
from mvt.android.artifacts.processes import Processes
from mvt.common.indicators import Indicators
from ..utils import get_artifact
class TestProcessesArtifact:
def test_parsing(self):
p = Processes()
file = get_artifact("android_data/ps.txt")
with open(file) as f:
data = f.read()
assert len(p.results) == 0
p.parse(data)
assert len(p.results) == 17
assert p.results[0]["proc_name"] == "init"
def test_ioc_check(self, indicator_file):
p = Processes()
file = get_artifact("android_data/ps.txt")
with open(file) as f:
data = f.read()
p.parse(data)
ind = Indicators(log=logging.getLogger())
ind.parse_stix2(indicator_file)
ind.ioc_collections[0]["processes"].append("lru-add-drain")
p.indicators = ind
assert len(p.detected) == 0
p.check_indicators()
assert len(p.detected) == 1