Malware writing - Python malware, part 1

I would like to point out there is an event-based method that performs better than GetAsncKeyState which is via SetWindowsHookEx with the WH_KEYBOARD_LL hook type that can install a global monitor on keystrokes. Please refer to LowLevelKeyboardProc for the callback function details. For an example (in C), you can refer to my previous thread on Windows Keylogging (shameless self-promotion :wink:).

Iā€™m assuming the reason you need this is because youā€™re building a console application. If you can get it to build with the Windows (GUI) subsystem, it removes the console prompt entirely, making this code redundant. Itā€™s also good to note that if you do this, you may need the Windows Message Loop to keep the application alive. Itā€™ll be needed to obtain messages for the keystrokes from SetWindowsHookEx as well.

As for the clipboard monitor, there are a few ways to do it. MSDN documents one way through GetClipboardSequenceNumber that uses a 32-bit ā€œclipboard sequence numberā€ to track different clipboard contents. It also documents an event-based listener with AddClipboardFormatListener with the WM_CLIPBOARDUPDATE window message (requires a window). Here is some PoC code that demonstrates the latter: ClipboardMonitor.c.

EDIT: I just realised that your code might not account for right-click ā†’ copy.

Looking forward to the rest of the series!

13 Likes