AndroidFridaManager 0.4__tar.gz → 0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,12 +12,26 @@ import lzma
12
12
  import re
13
13
  from shutil import copyfile
14
14
  import tempfile
15
+ import argparse
15
16
 
16
17
  # some parts are taken from ttps://github.com/Mind0xP/Frida-Python-Binding/
17
18
 
18
19
  class FridaManager():
19
20
 
20
21
  def __init__(self, is_remote=False, socket="", verbose=False, frida_install_dst="/data/local/tmp/"):
22
+ """
23
+ Constructor of the current FridaManager instance
24
+
25
+ :param is_remote: The number to multiply.
26
+ :type number: bool
27
+ :param socket: The socket to connect to the remote device. The remote device needs to be set by <ip:port>. By default this string will be empty in order to indicate that FridaManger is working with the first connected USB device.
28
+ :type number: string
29
+ :param verbose: Set the output to verbose, so that the logging information gets printed. By default set to False.
30
+ :type number: bool
31
+ :param frida_install_dst: The path where the frida server should be installed. By default it will be installed to /data/local/tmp/.
32
+ :type number: bool
33
+
34
+ """
21
35
  self.is_remote = is_remote
22
36
  self.device_socket = socket
23
37
  self.verbose = verbose
@@ -31,6 +45,10 @@ class FridaManager():
31
45
 
32
46
 
33
47
  def _setup_logging(self):
48
+ """
49
+ Setup logging for the current instance of FridaManager
50
+
51
+ """
34
52
  logger = logging.getLogger()
35
53
  logger.setLevel(logging.INFO)
36
54
  color_formatter = ColoredFormatter(
@@ -68,6 +86,13 @@ class FridaManager():
68
86
 
69
87
 
70
88
  def is_frida_server_running(self):
89
+ """
90
+ Checks if on the connected device a frida server is running.
91
+ The test is done by the Android system command pidof and is looking for the string frida-server.
92
+
93
+ :return: True if a frida-server is running otherwise False.
94
+ :rtype: bool
95
+ """
71
96
  result = self.run_adb_command_as_root("/system/bin/pidof frida-server")
72
97
  if len(result.stdout) > 1:
73
98
  return True
@@ -89,15 +114,28 @@ class FridaManager():
89
114
  self._adb_remove_file_if_exist(cmd)
90
115
 
91
116
 
92
- def install_frida_server(self,dst_dir="/data/local/tmp/"):
117
+ def install_frida_server(self, dst_dir="/data/local/tmp/", version="latest"):
118
+ """
119
+ Install the frida server binary on the Android device.
120
+ This includes downloading the frida-server, decompress it and pushing it to the Android device.
121
+ By default it is pushed into the /data/local/tmp/ directory.
122
+ Further the binary will be set to executable in order to run it.
123
+
124
+ :param dst_dir: The destination folder where the frida-server binary should be installed (pushed).
125
+ :type number: string
126
+ :param version: The version. By default the latest version will be used.
127
+ :type number: string
128
+
129
+ """
93
130
  if dst_dir is self.install_frida_server.__defaults__[0]:
94
131
  frida_dir = self.frida_install_dst
95
132
  else:
96
133
  frida_dir = dst_dir
97
134
 
98
135
  with tempfile.TemporaryDirectory() as dir:
99
- self.logger.info(f"[*] downloading frida-server to {dir}")
100
- file_path = self.download_frida_server(dir)
136
+ if self.verbose:
137
+ self.logger.info(f"[*] downloading frida-server to {dir}")
138
+ file_path = self.download_frida_server(dir,version)
101
139
  tmp_frida_server = self.extract_frida_server_comp(file_path)
102
140
  # ensure's that we always overwrite the current installation with our recent downloaded version
103
141
  self._adb_remove_file_if_exist(frida_dir + "frida-server")
@@ -107,18 +145,32 @@ class FridaManager():
107
145
 
108
146
  # by default the latest frida-server version will be downloaded
109
147
  def download_frida_server(self, path, version="latest"):
148
+ """
149
+ Downloads a frida server. By default the latest version is used.
150
+ If you want to download a specific version you have to provide it trough the version parameter.
151
+
152
+ :param path: The path where the compressed frida-server should be downloded.
153
+ :type number: string
154
+ :param version: The version. By default the latest version will be used.
155
+ :type number: string
156
+
157
+ :return: The location of the downloaded frida server in its compressed form.
158
+ :rtype: string
159
+ """
110
160
  url = self.get_frida_server_for_android_url(version)
111
161
  with open(path+"/frida-server","wb") as fsb:
112
162
  res = requests.get(url)
113
163
  fsb.write(res.content)
114
- self.logger.info(f"[*] writing frida-server to {path}")
164
+ if self.verbose:
165
+ self.logger.info(f"[*] writing frida-server to {path}")
115
166
 
116
167
  return path+"/frida-server"
117
168
 
118
169
 
119
170
 
120
171
  def extract_frida_server_comp(self, file_path):
121
- self.logger.info(f"[*] extracting {file_path} ...")
172
+ if self.verbose:
173
+ self.logger.info(f"[*] extracting {file_path} ...")
122
174
  # create a subdir for the specified filename
123
175
  frida_server_dir = file_path[:-3]
124
176
  os.makedirs(frida_server_dir)
@@ -153,19 +205,22 @@ class FridaManager():
153
205
 
154
206
  def _get_frida_server_donwload_url(self, arch, version):
155
207
  frida_download_prefix = "https://github.com/frida/frida/releases"
156
- url = "https://api.github.com/repos/frida/frida/releases/"+version
157
- try:
158
- res = requests.get(url)
159
- except requests.exceptions.TooManyRedirects:
160
- # invalid version therfore set to latest
161
- url = "https://api.github.com/repos/frida/frida/releases/latest"
162
- res = requests(url)
163
- except requests.exceptions.RequestException as e:
164
- print("[-] error in doing requests: "+e)
165
- exit(2)
166
208
 
167
- frida_server_path = re.findall(r'\/download\/\d+\.\d+\.\d+\/frida\-server\-\d+\.\d+\.\d+\-android\-'+arch+'\.xz',res.text)
168
- final_url = frida_download_prefix + frida_server_path[0]
209
+ if version is "latest":
210
+ url = "https://api.github.com/repos/frida/frida/releases/"+version
211
+
212
+ try:
213
+ res = requests.get(url)
214
+ except requests.exceptions.RequestException as e:
215
+ print("[-] error in doing requests: "+e)
216
+ exit(2)
217
+
218
+ frida_server_path = re.findall(r'\/download\/\d+\.\d+\.\d+\/frida\-server\-\d+\.\d+\.\d+\-android\-'+arch+'\.xz',res.text)
219
+ final_url = frida_download_prefix + frida_server_path[0]
220
+
221
+ else:
222
+ final_url = "https://github.com/frida/frida/releases/download/"+ version +"/frida-server-"+version+"-android-"+arch+".xz"
223
+
169
224
 
170
225
  if self.verbose:
171
226
  print(f"[*] frida-server download url: {final_url}")
@@ -242,10 +297,39 @@ class FridaManager():
242
297
  if self._adb_does_file_exist(path):
243
298
  output = self.run_adb_command_as_root("rm "+path)
244
299
 
245
- # only there in order to do some tests will be removed soon
246
- #if __name__ == "__main__":
247
- # afm_obj = FridaManager()
248
- # afm_obj.install_frida_server()
249
- # result = afm_obj.is_frida_server_running()
250
- # print(result)
300
+
301
+
302
+ if __name__ == "__main__":
303
+ if len(sys.argv) > 1:
304
+ parser = argparse.ArgumentParser(description='FridaManager initialization parameters.')
305
+
306
+ parser.add_argument('--is_remote', type=lambda x: (str(x).lower() == 'true'), default=False, help='Whether to use Frida in remote mode. Default is False.')
307
+ parser.add_argument('--socket', type=str, default="", help='Socket to use for the connection. Expected in the format <ip:port>.')
308
+ parser.add_argument('--verbose', action='store_true', default=False, help='Enable verbose output. Default is False.')
309
+ parser.add_argument('--frida_install_dst', type=str, default="/data/local/tmp/", help='Frida installation destination. Default is "/data/local/tmp/".')
310
+ parser.add_argument('-r','--is_running', type=bool, default=False, help='Checks only if frida-server is running on the Android device or not.')
311
+
312
+ args = parser.parse_args()
313
+
314
+ if args.is_running:
315
+ afm_obj = FridaManager()
316
+ if afm_obj.is_frida_server_running():
317
+ print("[*] frida-server is running on Android device")
318
+ else:
319
+ print("[*] frida-server is not running on Android device")
320
+
321
+ sys.exit()
322
+
323
+
324
+
325
+ afm_obj = FridaManager(args.is_remote, args.socket, args.verbose, args.frida_install_dst)
326
+ else:
327
+ afm_obj = FridaManager()
328
+
329
+ afm_obj.install_frida_server()
330
+ result = afm_obj.is_frida_server_running()
331
+ if result:
332
+ print("[*] succesfull installed and launched latest frida-server version on Android device")
333
+ else:
334
+ print("[-] unable to run frida-server on Android device")
251
335
 
@@ -1,8 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: AndroidFridaManager
3
- Version: 0.4
3
+ Version: 0.8
4
4
  Summary: A python API in order to install and run the frida-server on an Android device.
5
5
  Home-page: https://github.com/fkie-cad/AndroidFridaManager
6
+ Author: Daniel Baier
6
7
  Author-email: daniel.baier@fkie.fraunhofer.de
7
8
  License: GPL v3
8
9
  Keywords: mobile,instrumentation,frida,hook,android
@@ -28,20 +29,39 @@ Just install it via pip:
28
29
  pip install AndroidFridaManager
29
30
  ```
30
31
 
32
+ This will install the `afrim`-command to your system.
33
+
31
34
  ## Usage
32
35
 
36
+ In order to easily install the latest frida-server version to your Android device just run the following command:
37
+
38
+ ```bash
39
+ $ afrim
40
+ ```
41
+
42
+
43
+ In order to check only if frida-server is running invoke it with the `-r`-parameter:
44
+
45
+ ```bash
46
+ $ afrim -r
47
+ ```
48
+
49
+
50
+ ## API Usage
51
+
33
52
  ```python
34
53
  from AndroidFridaManager import FridaManager
35
-
54
+ ...
36
55
  afm_obj = FridaManager(is_remote=False, socket="ip:port", verbose=False, frida_install_dst="/data/local/tmp/")
37
56
  afm_obj.install_frida_server()
38
57
  afm_obj.run_frida_server()
39
58
  ```
40
59
 
60
+
41
61
  ## API
42
62
 
43
63
  ```python
44
- install_frida_server(version="latest")
64
+ install_frida_server(dst_dir="/data/local/tmp/", version="latest")
45
65
  run_frida_server()
46
66
  is_frida_server_running()
47
67
  stop_frida_server()
@@ -6,5 +6,6 @@ AndroidFridaManager/__init__.py
6
6
  AndroidFridaManager.egg-info/PKG-INFO
7
7
  AndroidFridaManager.egg-info/SOURCES.txt
8
8
  AndroidFridaManager.egg-info/dependency_links.txt
9
+ AndroidFridaManager.egg-info/entry_points.txt
9
10
  AndroidFridaManager.egg-info/requires.txt
10
11
  AndroidFridaManager.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ afrim = AndroidFridaManager.FridaManger:main
@@ -1,8 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: AndroidFridaManager
3
- Version: 0.4
3
+ Version: 0.8
4
4
  Summary: A python API in order to install and run the frida-server on an Android device.
5
5
  Home-page: https://github.com/fkie-cad/AndroidFridaManager
6
+ Author: Daniel Baier
6
7
  Author-email: daniel.baier@fkie.fraunhofer.de
7
8
  License: GPL v3
8
9
  Keywords: mobile,instrumentation,frida,hook,android
@@ -28,20 +29,39 @@ Just install it via pip:
28
29
  pip install AndroidFridaManager
29
30
  ```
30
31
 
32
+ This will install the `afrim`-command to your system.
33
+
31
34
  ## Usage
32
35
 
36
+ In order to easily install the latest frida-server version to your Android device just run the following command:
37
+
38
+ ```bash
39
+ $ afrim
40
+ ```
41
+
42
+
43
+ In order to check only if frida-server is running invoke it with the `-r`-parameter:
44
+
45
+ ```bash
46
+ $ afrim -r
47
+ ```
48
+
49
+
50
+ ## API Usage
51
+
33
52
  ```python
34
53
  from AndroidFridaManager import FridaManager
35
-
54
+ ...
36
55
  afm_obj = FridaManager(is_remote=False, socket="ip:port", verbose=False, frida_install_dst="/data/local/tmp/")
37
56
  afm_obj.install_frida_server()
38
57
  afm_obj.run_frida_server()
39
58
  ```
40
59
 
60
+
41
61
  ## API
42
62
 
43
63
  ```python
44
- install_frida_server(version="latest")
64
+ install_frida_server(dst_dir="/data/local/tmp/", version="latest")
45
65
  run_frida_server()
46
66
  is_frida_server_running()
47
67
  stop_frida_server()
@@ -9,20 +9,39 @@ Just install it via pip:
9
9
  pip install AndroidFridaManager
10
10
  ```
11
11
 
12
+ This will install the `afrim`-command to your system.
13
+
12
14
  ## Usage
13
15
 
16
+ In order to easily install the latest frida-server version to your Android device just run the following command:
17
+
18
+ ```bash
19
+ $ afrim
20
+ ```
21
+
22
+
23
+ In order to check only if frida-server is running invoke it with the `-r`-parameter:
24
+
25
+ ```bash
26
+ $ afrim -r
27
+ ```
28
+
29
+
30
+ ## API Usage
31
+
14
32
  ```python
15
33
  from AndroidFridaManager import FridaManager
16
-
34
+ ...
17
35
  afm_obj = FridaManager(is_remote=False, socket="ip:port", verbose=False, frida_install_dst="/data/local/tmp/")
18
36
  afm_obj.install_frida_server()
19
37
  afm_obj.run_frida_server()
20
38
  ```
21
39
 
40
+
22
41
  ## API
23
42
 
24
43
  ```python
25
- install_frida_server(version="latest")
44
+ install_frida_server(dst_dir="/data/local/tmp/", version="latest")
26
45
  run_frida_server()
27
46
  is_frida_server_running()
28
47
  stop_frida_server()
@@ -2,7 +2,7 @@ import os
2
2
  from setuptools import setup, find_packages
3
3
  from os.path import abspath, dirname, join
4
4
 
5
- __version__ = 0.4
5
+ __version__ = "0.8"
6
6
  __author__ = "Daniel Baier"
7
7
 
8
8
  # Fetches the content from README.md
@@ -37,7 +37,7 @@ setup(
37
37
 
38
38
  url="https://github.com/fkie-cad/AndroidFridaManager",
39
39
 
40
- author_name=__author__,
40
+ author=__author__,
41
41
  author_email="daniel.baier@fkie.fraunhofer.de",
42
42
  license='GPL v3',
43
43
 
@@ -69,9 +69,9 @@ setup(
69
69
  # This field is OPTIONAL
70
70
  keywords=["mobile", "instrumentation", "frida", "hook", "android"],
71
71
 
72
- #entry_points={
73
- # 'console_scripts': [
74
- # 'ammm=ammm:main',
75
- # ],
76
- #},
72
+ entry_points={
73
+ 'console_scripts': [
74
+ 'afrim=AndroidFridaManager.FridaManger:main',
75
+ ],
76
+ },
77
77
  )