Skip to content

Commit 8f88c13

Browse files
authored
Add compatibility with new DEX module (#94)
Also, - rewrite a lot of the code - add tests - add travisci integration - clean up rules
1 parent f0611c7 commit 8f88c13

27 files changed

+699
-408
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test-data
2+
research
3+
4+
venv
5+
6+
.idea
7+
.pytest_cache
8+
apkid.egg-info

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# precompiled rules included in dist but not source
22
apkid/rules/rules.yarc
33

4-
# Apks and dex files for testing
4+
# APKs and DEX files for local testing
55
test-data
66
research
7+
78
### VirtualEnv template
89
# Virtualenv
910
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
@@ -318,6 +319,7 @@ nosetests.xml
318319
coverage.xml
319320
*,cover
320321
.hypothesis/
322+
.pytest_cache/
321323

322324
# Translations
323325
*.mo

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: python
2+
dist: trusty
3+
cache:
4+
pip: true
5+
# directories:
6+
# - $HOME/.cache/samples
7+
python:
8+
- "2.7"
9+
- "3.6"
10+
install:
11+
- git clone --recursive https://github.com/rednaga/yara-python-1 yara-python
12+
- cd yara-python
13+
- CFLAGS="-std=gnu99" python setup.py build --enable-dex install
14+
- cd ../
15+
- pip install -e .
16+
script:
17+
- ./prep-release.py | true
18+
- pytest

docker/Dockerfile renamed to Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
FROM python:2.7-slim
22

33
RUN apt-get update -qq && apt-get install -y git build-essential gcc pandoc
4-
54
RUN pip install --upgrade pip
6-
RUN git clone https://github.com/rednaga/yara-python.git
5+
6+
RUN git clone --recursive https://github.com/rednaga/yara-python-1.git yara-python
77
WORKDIR yara-python
8-
RUN python setup.py install
8+
RUN CFLAGS="-std=gnu99" python setup.py build --enable-dex install
9+
910
RUN mkdir /apkid
1011
COPY ./ /apkid/
1112
WORKDIR /apkid

README.md

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,77 @@
11
# APKiD
22

3+
[![Build Status](https://travis-ci.org/rednaga/APKiD.svg?branch=master)](https://travis-ci.org/rednaga/APKiD)
4+
35
APKiD gives you information about how an APK was made. It identifies many compilers, packers, obfuscators, and other weird stuff. It's _PEiD_ for Android.
46

5-
For more information on what this tool can be used for, check out:
7+
For more information on what this tool can be used for check out:
68

79
* [Android Compiler Fingerprinting](http://hitcon.org/2016/CMT/slide/day1-r0-e-1.pdf)
810
* [Detecting Pirated and Malicious Android Apps with APKiD](http://rednaga.io/2016/07/31/detecting_pirated_and_malicious_android_apps_with_apkid/)
911

1012
# Installing
1113

12-
The _yara-python_ clone and compile steps here are temporarily necessary because we must point directly to our modified version of a _Yara_ branch which includes our DEX Yara module. This step is nessecary until (if?) the original maintainers of _Yara_ merge our module into the master branch. When this happens, we will undate the instructions here. After the _yara-python_ fork is compiled, you can use `pip` to the most currently published `APKiD` package.
14+
Unfortunately, you can't just `pip install` APKiD since it depends on RedNaga's custom fork of [yara-python](https://github.com/rednaga/yara-python-1).
15+
16+
First, install our yara-python fork:
1317

1418
```bash
15-
git clone --recursive https://github.com/rednaga/yara-python
19+
git clone --recursive https://github.com/rednaga/yara-python-1 yara-python
1620
cd yara-python
17-
python setup.py install
21+
python setup.py build --enable-dex install
22+
```
23+
24+
Then, you can install apkid normally:
25+
```bash
1826
pip install apkid
1927
```
2028

21-
## Docker install
29+
This extra step is necessary until yara-python is updated with a version of Yara which includes the new, experimental DEX module.
30+
31+
## Docker
2232

23-
In an attempt to reduce the support ticket we receive from the above instructions being hard to follow, there is
24-
a docker file and script which can be used for processing files quickly. This also serves as a proof that the above
25-
instructions _do_ work! This usage, of course, requires that you have docker correctly installed on your machine. However the following instructions should "just work" if you have docker and git install on a machine:
33+
If installing is too complicated, you can just use [Docker](https://www.docker.com/community-edition)! Of course, this usage requires that you have git and docker installed on your machine.
34+
35+
Here's how to use Docker:
2636

2737
```bash
2838
git clone https://github.com/rednaga/APKiD
2939
cd APKiD/
30-
docker-compose build
31-
cd docker/
32-
./apkid.sh ~/reverse/targets/android/example/example.apk
33-
[+] APKiD 1.0.0 :: from RedNaga :: rednaga.io
40+
docker build . -t rednaga:apkid
41+
docker/apkid.sh ~/reverse/targets/android/example/example.apk
42+
[+] APKiD 1.2.1 :: from RedNaga :: rednaga.io
3443
[*] example.apk!classes.dex
3544
|-> compiler : dx
3645
```
3746

3847
# Usage
3948

4049
```
41-
usage: apkid [-h] [-j] [-t TIMEOUT] [-o DIR] [FILE [FILE ...]]
50+
usage: apkid [-h] [-j] [-t TIMEOUT] [-o DIR] [-q] [FILE [FILE ...]]
4251
43-
APKiD - Android Application Identifier v1.0.0
52+
APKiD - Android Application Identifier v1.2.1
4453
4554
positional arguments:
46-
FILE apk, dex, or directory
55+
FILE apk, dex, or directory
4756
4857
optional arguments:
49-
-h, --help show this help message and exit
50-
-j, --json output results in JSON format
51-
-t TIMEOUT, --timeout TIMEOUT
52-
Yara scan timeout (in seconds)
53-
-o DIR, --output-dir DIR
54-
write individual JSON results to this directory
58+
-h, --help show this help message and exit
59+
-j, --json output scan results in JSON format
60+
-t TIMEOUT, --timeout TIMEOUT Yara scan timeout (in seconds)
61+
-o DIR, --output-dir DIR write individual results to this directory (implies --json)
62+
-q, --quiet suppress extraneous output
5563
```
5664

5765
# Submitting New Packers / Compilers / Obfuscators
5866

5967
If you come across an APK or DEX which APKiD does not recognize, please open a GitHub issue and tell us:
68+
6069
* what you think it is
6170
* the file hash (either MD5, SHA1, SHA256)
6271

63-
We are open to any type of concept you might have for "something interesting" to detect, so do not limit yourself solely to packers, compilers or obfuscators. If there is an interesting anti disassembler, anti vm, anti* trick, please make an issue.
72+
We are open to any type of concept you might have for "something interesting" to detect, so do not limit yourself solely to packers, compilers or obfuscators. If there is an interesting anti-disassembler, anti-vm, anti-* trick, please make an issue.
6473

65-
You're also welcome to submit pull requests. Just be sure to include a file hash so we can check the rule.
74+
Pull requests are welcome. If you're submitting a new rule, be sure to include a file hash of the APK / DEX so we can check the rule.
6675

6776
# License
6877

@@ -72,15 +81,15 @@ Depending on your needs, you must choose one of them and follow its policies. A
7281

7382
# Hacking
7483

75-
First you will need to install the specific version of _yara-python_ the project depends on (more information about this in the _Installing_ section):
84+
First, you'll need to install our fork of _yara-python_:
7685

7786
```bash
78-
git clone --recursive https://github.com/rednaga/yara-python
87+
git clone --recursive https://github.com/rednaga/yara-python-1 yara-python
7988
cd yara-python
80-
python setup.py install
89+
python setup.py build --enable-dex install
8190
```
8291

83-
Then, clone this repo, compile the rules, and install the package in editable mode:
92+
Then, clone this repository, compile the rules, and install the package in editable mode:
8493

8594
```bash
8695
git clone https://github.com/rednaga/APKiD
@@ -94,3 +103,20 @@ If the above doesn't work, due to permission errors dependent on your local mach
94103
```bash
95104
pip install -e .[dev] --user
96105
```
106+
107+
If you update any of the rules, be sure to run `prep-release.py` to recompile them.
108+
109+
# For Maintainers
110+
111+
This section is for package maintainers.
112+
113+
To update the PyPI package:
114+
115+
```bash
116+
./prep-release.py readme
117+
rm dist/*
118+
python setup.py sdist bdist_wheel
119+
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
120+
```
121+
122+
For more information see [Packaging Projects](https://packaging.python.org/tutorials/packaging-projects/).

0 commit comments

Comments
 (0)