Created
December 1, 2019 18:30
-
-
Save fwaeytens/ec109fc74408829e29e9577d72170455 to your computer and use it in GitHub Desktop.
frida-example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import frida | |
import sys | |
def on_message(message, data): | |
if message['type'] == 'send': | |
print(message['payload']) | |
elif message['type'] == 'error': | |
print(message['stack']) | |
else: | |
print(message) | |
try: | |
mgr = frida.get_device_manager() | |
device = mgr.add_remote_device("192.168.93.129:27042") | |
#pid = device.spawn("C:\\Windows\\System32\\notepad.exe") | |
session = device.attach("notepad.exe") | |
print("Attached to notepad.exe") | |
except Exception as e: | |
print(f"Error => {e}") | |
sys.exit(0) | |
script = session.create_script(""" | |
var baseAddr = Module.findBaseAddress('user32.dll'); | |
console.log('Kernel32.dll baseAddr: ' + baseAddr); | |
var SetWindowTextW_address = Module.findExportByName("user32.dll", "SetWindowTextW"); | |
console.log('SetWindowTextW address: ' + SetWindowTextW_address); | |
// Attach a hook to the native pointer | |
Interceptor.attach(SetWindowTextW_address, { | |
onEnter: function (args, state) { | |
var handle = args[0]; | |
var title = args[1].readUtf16String(); | |
console.log("Window Handle : "+handle); | |
console.log('user32!SetWindowTextW()'+":"+ title); | |
if (title.includes("Notepad")){ | |
args[1].writeUtf16String("Injected!"); | |
} | |
}, | |
onLeave: function (retval) { | |
} | |
}); | |
""") | |
script.on('message', on_message) | |
script.load() | |
try: | |
while True: | |
pass | |
except KeyboardInterrupt: | |
session.detach() | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment