r/Batch • u/Miich64 • Mar 26 '20
Question (Solved) Keylogger batch script
Hi, i was wondering if it's possible to make a keylogger with a batch script. I don't want any code, i'm just curious if it's possible :)
1
u/SereousBlack Mar 26 '20
You should use vbs for that. It is easy to learn and you can just search for vbs keylogger on youtube.
1
Mar 26 '20
Possible, yes, but not ideal.
1
u/Lusankya Mar 26 '20
Burden of proof is on you here. How could a Batch script capture keystrokes outside of its session? You need to hook into winapi for that, and pure Batch doesn't have any callback capabilities. The only solutions I can think of all require VBScript or some other handler to then execute your Batch, but I wouldn't call that a "Batch keylogger."
1
u/jcunews1 Mar 27 '20
By VBScript, if you meant WSH or HTA, it's not possible by itself. It'll need at least .NET code (e.g. C#, VB.NET, JScript.NET) which is either run under PowerShell, or from a compiled binary. Other than that, it'll require third party or additional tool.
1
u/Lusankya Mar 27 '20
You could do it purely in VBScript via WSH by creating your own COM pseudo-object to handle the callback and invoke your script.
This is all very much in the realm of "just because you can, doesn't mean you should."
1
u/jcunews1 Mar 28 '20
The fact that it requires COM compiled from a .NET source code, means that it's not VBScript. That's basically an additional tool.
1
u/Lusankya Mar 28 '20
You can build COM objects without dotNet. How else do you think we did COM between 1993 and 2002?
That article shows how to trick Windows into registering a WSH instance as a COM object without the use of any special binaries. You don't need to build anything to make it work.
1
u/jcunews1 Mar 28 '20
For key logging feature, something need to be custom made in order to be usable from WSH. Meaning that's it's not part of WSH. i.e. key logging can't be done using WSH by itself.
1
u/Lusankya Mar 28 '20
WSH can make winapi calls. All you need to do is register a handler for GetAsyncKeyState, and retrigger it every time it fires. GetAsyncKeyState reads the keyboard state directly, which gets around the focus issues when hooking on WM_KEY* messages.
All of this can be done purely in VBScript via WSH, as long as you register your WSH session as a COM pseudo-object so the script can receive the winapi callbacks.
Any modern AV should detect this behaviour via heuristics, as it's an attack vector as old as winapi itself.
1
u/jcunews1 Mar 29 '20
Without that COM pseudo-object - regardless of how it is made, WSH can not call Windows API. Meaning that, that COM pseudo-object is not part of WSH.
1
u/Lusankya Mar 29 '20
The pseudo-object IS the WSH instance. You just create the appropriate registry entries to register the instance itself as a COM object. The messages are coming directly from winapi into WSH with nothing in between.
It's called a pseudo-object because it's not a true COM object; it does not persist across instances. If you close your WSH instance, you need to re-register the new instance as a COM object for it to work.
→ More replies (0)
1
u/Shadow_Thief Mar 27 '20
Not in pure batch in any meaningful way. Batch can't take user input unless the cmd window is active, and if people see that they're typing into the command prompt instead of anywhere else, that defeats the entire purpose of a keylogger.