forked from Nightbringer21/fridump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfridump.py
More file actions
175 lines (150 loc) · 4.97 KB
/
fridump.py
File metadata and controls
175 lines (150 loc) · 4.97 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import textwrap
import frida
import os
import sys
import frida.core
import dumper
import utils
import argparse
import logging
class Fridump:
def __init__(self, App_Name = None, Directory = None, USB = False, Remote = False, Debug_Level = logging.INFO, Strings = False, Max_Size = 20971520, Perms = 'rw-'):
self.arguments = None
self.session = None
self.parser = None
self.App_Name = App_Name
self.Directory = Directory
self.USB = USB
self.Remote = Remote
self.Debug_Level = Debug_Level
self.Strings = Strings
self.Max_Size = Max_Size
self.Perms = Perms
self.mem_access_viol = ""
def MENU(self):
logo = """
______ _ _
| ___| (_) | |
| |_ _ __ _ __| |_ _ _ __ ___ _ __
| _| '__| |/ _` | | | | '_ ` _ \| '_ \\
| | | | | | (_| | |_| | | | | | | |_) |
\_| |_| |_|\__,_|\__,_|_| |_| |_| .__/
| |
|_|
"""
self.parser = argparse.ArgumentParser(
prog='fridump',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent(""))
self.parser.add_argument('process',
help='the process that you will be injecting to')
self.parser.add_argument('-o', '--out', type=str, metavar="dir",
help='provide full output directory path. (def: \'dump\')')
self.parser.add_argument('-U', '--usb', action='store_true',
help='device connected over usb')
self.parser.add_argument('-R', '--remote', action='store_true',
help='device connected over network')
self.parser.add_argument('-v', '--verbose', action='store_true',
help='verbose')
self.parser.add_argument('-r', '--read_only', action='store_true',
help="dump read-only parts of memory. More data, more errors")
self.parser.add_argument('-s', '--strings', action='store_true',
help='run strings on all dump files. Saved in output dir.')
self.parser.add_argument('--max-size', type=int, metavar="bytes",
help='maximum size of dump file in bytes (def: 20971520)')
#Used to assing parsed information
self.arguments = self.parser.parse_args()
self.USB = self.arguments.usb
self.Remote = self.arguments.remote
self.Strings = self.arguments.strings
self.App_Name = self.arguments.process
self.Directory = self.arguments.out
if self.arguments.read_only:
self.Perms = 'r--'
else:
self.Perms = 'rw--'
self.Debug_Level = self.arguments.verbose
print(logo)
def String(self):
files = os.listdir(self.Directory)
i = 0
l = len(files)
for f1 in files:
utils.strings(f1, self.Directory)
i += 1
utils.printProgress(i, l, prefix='Progress:', suffix='Complete', bar=50)
print("Finished!")
def Session(self):
print(self.App_Name)
try:
if self.USB:
self.session = frida.get_usb_device().attach(self.App_Name)
elif self.Remote:
self.session = frida.get_remote_device().attach(self.App_Name)
else:
self.session = frida.attach(self.App_Name)
except Exception as e:
print("Cant connect to application. Have you connected the device?")
logging.debug(str(e))
sys.exit()
def Dir(self):
if self.Directory != None:
print(self.Directory)
if os.path.isdir(self.Directory):
print("Output directory is set to: ", self.Directory)
else:
print("The selected output directory does not exist!")
sys.exit(1)
else:
print("Current directory: ", str(os.getcwd()))
place = os.path.join(os.getcwd(), "dump")
self.Directory = place
if not os.path.exists(place):
print("Creating directory...")
os.makedirs(place)
def Script(self):
print("Starting Memory dump...")
script = self.session.create_script(
"""'use strict';
rpc.exports = {
enumerateRanges: function (prot) {
return Process.enumerateRangesSync(prot);
},
readMemory: function (address, size) {
return Memory.readByteArray(ptr(address), size);
}
};
""")
script.on("message", utils.on_message)
script.load()
agent = script.exports
print(self.Perms)
ranges = agent.enumerate_ranges(self.Perms)
if self.Max_Size is not None:
MAX_SIZE = self.Max_Size
i = 0
l = len(ranges)
# Performing the memory dump
for range in ranges:
base = range["base"]
size = range["size"]
logging.debug("Base Address: " + str(base))
logging.debug("")
logging.debug("Size: " + str(size))
if size > MAX_SIZE:
logging.debug("Too big, splitting the dump into chunks")
self.mem_access_viol = dumper.splitter(
agent, base, size, MAX_SIZE, self.mem_access_viol, self.Directory)
continue
self.mem_access_viol = dumper.dump_to_file(
agent, base, size, self.mem_access_viol, self.Directory)
i += 1
utils.printProgress(i, l, prefix='Progress:', suffix='Complete', bar=50)
print("")
if self.Strings:
self.String()
testobj = Fridump( )
testobj.MENU()
testobj.Session()
testobj.Dir()
testobj.Script()