Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated script to find and attach to open processes without reopening… #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/dumper.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/utils.cpython-310.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def dump_to_file(agent,base,size,error,directory):
def splitter(agent,base,size,max_size,error,directory):
times = size/max_size
diff = size % max_size
if diff is 0:
if diff == 0:
logging.debug("Number of chunks:"+str(times+1))
else:
logging.debug("Number of chunks:"+str(times))
Expand All @@ -33,7 +33,7 @@ def splitter(agent,base,size,max_size,error,directory):
dump_to_file(agent, cur_base, max_size, error, directory)
cur_base = cur_base + max_size

if diff is not 0:
if diff != 0:
logging.debug("Save bytes: "+str(hex(cur_base))+" till "+str(hex(cur_base+diff)))
dump_to_file(agent, cur_base, diff, error, directory)

40 changes: 27 additions & 13 deletions fridump.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def MENU():
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent(""))

parser.add_argument('process',
help='the process that you will be injecting to')
parser.add_argument('-A', '--appname', help='the application name that you will be injecting to', required=False)
parser.add_argument('-o', '--out', type=str, metavar="dir",
help='provide full output directory path. (def: \'dump\')')
parser.add_argument('-U', '--usb', action='store_true',
Expand All @@ -39,6 +38,7 @@ def MENU():
help="dump read-only parts of memory. More data, more errors")
parser.add_argument('-s', '--strings', action='store_true',
help='run strings on all dump files. Saved in output dir.')
parser.add_argument('-p', '--pid', help='attach direct to a process id', required=False)
parser.add_argument('--max-size', type=int, metavar="bytes",
help='maximum size of dump file in bytes (def: 20971520)')
args = parser.parse_args()
Expand All @@ -50,13 +50,14 @@ def MENU():
arguments = MENU()

# Define Configurations
APP_NAME = arguments.process
APP_NAME = arguments.appname
DIRECTORY = ""
USB = arguments.usb
DEBUG_LEVEL = logging.INFO
STRINGS = arguments.strings
MAX_SIZE = 20971520
PERMS = 'rw-'
pid = 0

if arguments.read_only:
PERMS = 'r--'
Expand All @@ -69,12 +70,25 @@ def MENU():
# Start a new Session
session = None
try:
if arguments.pid is not None:
pid = arguments.pid
pass
else:
for a in frida.get_usb_device().enumerate_applications():
if a.identifier == APP_NAME:
pid = a.pid
break
pass

print(f"[+] attaching to process with Id of {pid}")
if USB:
session = frida.get_usb_device().attach(APP_NAME)
session = frida.get_usb_device().attach(int(pid))
else:
session = frida.attach(APP_NAME)
session = frida.attach(int(pid))

except Exception as e:
print("Can't connect to App. Have you connected the device?")
print(e)
print("[-] Can't connect to App. Have you connected the device?")
logging.debug(str(e))
sys.exit()

Expand All @@ -83,22 +97,22 @@ def MENU():
if arguments.out is not None:
DIRECTORY = arguments.out
if os.path.isdir(DIRECTORY):
print("Output directory is set to: " + DIRECTORY)
print("[*] Output directory is set to: " + DIRECTORY)
else:
print("The selected output directory does not exist!")
print("[*] The selected output directory does not exist!")
sys.exit(1)

else:
print("Current Directory: " + str(os.getcwd()))
print("[*] Current Directory: " + str(os.getcwd()))
DIRECTORY = os.path.join(os.getcwd(), "dump")
print("Output directory is set to: " + DIRECTORY)
print("[*] Output directory is set to: " + DIRECTORY)
if not os.path.exists(DIRECTORY):
print("Creating directory...")
print("[*] Creating directory...")
os.makedirs(DIRECTORY)

mem_access_viol = ""

print("Starting Memory dump...")
print("[+] Starting Memory dump...")

script = session.create_script(
"""'use strict';
Expand All @@ -116,7 +130,7 @@ def MENU():
script.on("message", utils.on_message)
script.load()

agent = script.exports
agent = script.exports_sync
ranges = agent.enumerate_ranges(PERMS)

if arguments.max_size is not None:
Expand Down
1 change: 1 addition & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def printProgress (times, total, prefix ='', suffix ='', decimals = 2, bar = 100
def strings(filename, directory, min=4):
strings_file = os.path.join(directory, "strings.txt")
path = os.path.join(directory, filename)
print(path)
with open(path, encoding='Latin-1') as infile:
str_list = re.findall("[\x20-\x7E]+\x00", infile.read())
with open(strings_file, "a") as st:
Expand Down