Skip to content
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
10 changes: 5 additions & 5 deletions ioctl_hunter/frida/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ var open_handles = {}
//

rpc.exports = {
exclude_ioctl: function (ioctl) {
excluded_ioctl.push(+ioctl);
excludeioctl: function (ioctl) {
excluded_ioctl.push(ioctl);
return excluded_ioctl;
},
sethookenabled: function (bool) {
Expand Down Expand Up @@ -98,13 +98,13 @@ function getPathByHandle(handle) {
var ret = Func_NtQueryObject(handle, 1, ptr, 1024, ptr2)

if (x32) {
var path = Memory.readUtf16String(ptr.add(8)) // 32 bits binaries
var path = Memory.readUtf16String(Memory.readPointer(ptr.add(8))) // 32 bits binaries
}
else {
var path = Memory.readUtf16String(ptr.add(16)) // 64 bits binaries
var path = Memory.readUtf16String(Memory.readPointer(ptr.add(16))) // 64 bits binaries
}

return path
return path.replaceAll("\\", "\\\\")
}

//
Expand Down
34 changes: 14 additions & 20 deletions ioctl_hunter/lib/hooking.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,27 @@ def check_drivers_filters(ioctl_dict):
ioctl_dict["handle_path"] != "N/A"
and driver.lower() in ioctl_dict["handle_path"].lower()
):
return False
return True
return False

ret = False
if State.results.excluded_drivers:
elif State.results.excluded_drivers:
for driver in State.results.excluded_drivers:
if (
ioctl_dict["handle_path"] != "N/A"
and driver.lower() in ioctl_dict["handle_path"].lower()
):
ret = True
break
return False

return ret
return True


def check_ioctls_filters(ioctl_dict):
if (
State.results.included_ioctls
and ioctl_dict["ioctl"] in State.results.included_ioctls
):
return False
if (
State.results.excluded_ioctls
and ioctl_dict["ioctl"] in State.results.excluded_ioctls
):
if State.results.included_ioctls:
return ioctl_dict["ioctl"] in State.results.included_ioctls
elif State.results.excluded_ioctls:
return ioctl_dict["ioctl"] not in State.results.excluded_ioctls
else:
return True
return False


def process_device_ioctl_queue():
Expand Down Expand Up @@ -86,10 +80,10 @@ def process_device_ioctl_queue():
logger.error(open_handles)
ioctl_dict["handle_path"] = "N/A"

if check_drivers_filters(ioctl_dict):
if not check_drivers_filters(ioctl_dict):
continue

if check_ioctls_filters(ioctl_dict):
if not check_ioctls_filters(ioctl_dict):
continue

device, access, function, method = get_ioctl_code_details(ioctl_dict["ioctl"])
Expand Down Expand Up @@ -160,7 +154,7 @@ def start_hooking(exe_path=None, pid=None, args=None, x32=False, all_symbols=Fal
State.script.exports.setHookEnabled(State.hook_enabled)

for ioctl in State.results.excluded_ioctls:
State.script.exports.exclude_ioctl(ioctl)
State.script.exports.excludeioctl(ioctl)

logger.info("Start hunting juicy IOCTLs")
while State.running and psutil.pid_exists(pid):
Expand All @@ -176,4 +170,4 @@ def start_hooking(exe_path=None, pid=None, args=None, x32=False, all_symbols=Fal
print_final_recap()
except:
pass
return True
return True