forked from shivsahni/APKEnum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apk-enum
executable file
·73 lines (60 loc) · 2.42 KB
/
apk-enum
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
#!/usr/bin/env python3
import os
import sys
import re
import threading
import logging
import argparse
import tempfile
from apkenum.report import Report, ReportSection, TextReportFormatter
from apkenum.extraction import URLsExtractor, IPsExtractor, S3BucketsExtractor, S3URLsExtrctor, APKSource, PermissionsExtractor
logger = logging.getLogger(__name__)
class ReportRunner:
def __init__(self, apk_source, sections_extractors):
self.apk_source = apk_source
self.sections_extractors = sections_extractors
def build_report(self):
report = Report()
self._mine()
for (section, extractor) in self.sections_extractors:
section.add_all_values(extractor.results())
report.add_section(section)
return report
def _mine(self):
logger.info("Analyzing APK")
self.apk_source.analyze()
logger.info("Running extractors");
for (_, extractor) in self.sections_extractors:
logger.info("Running extractor %s", extractor)
try:
extractor.process(self.apk_source)
except Exception as exc:
logger.error("Error processing apk")
logger.error(exc)
####################################################################################################
def main(args):
# Parse the command line arguments
argsparser = argparse.ArgumentParser(description="Find interesting things in Android APKs")
argsparser.add_argument('-a', '--apk', help="The APK file to decompile")
parsedargs = argsparser.parse_args(args)
apk_path = None
if parsedargs.apk is not None:
apk_path = parsedargs.apk
else:
argsparser.print_usage()
sys.exit(1)
apk_source = APKSource(apk_path)
sections_extractors = [
(ReportSection("URLs"), URLsExtractor()),
(ReportSection("IPs"), IPsExtractor()),
(ReportSection("S3 Buckets"), S3BucketsExtractor()),
(ReportSection("S3 URLs"), S3URLsExtrctor()),
(ReportSection("Permisssions"), PermissionsExtractor())
]
report_runner = ReportRunner(apk_source, sections_extractors)
report = report_runner.build_report()
formatter = TextReportFormatter()
formatter.write_report(report, sys.stdout)
####################################################################################################
if __name__ == '__main__':
main(sys.argv[1:])