Sign in to follow this  
Followers 0
Dr. Z2A

taking input from outside the window in C

17 posts in this topic

Ok, I thought it would be interesting to write a simple keylogger in C and I am able to take characters and put them in a log as someone types them from inside a command line window, but I have no clue how I would take input if the windows was minimized. I am very curious to know how taking input from outside the window would work. Can anyone explain to me how this kind of thing would be executed?

0

Share this post


Link to post
Share on other sites

I don't know the exact code, but you might be able to monitor the keyboard buffer.

0

Share this post


Link to post
Share on other sites

I remember doing something like this in assembly class, It involved connecting to the keyboard port.

0

Share this post


Link to post
Share on other sites

how would i connect to the keyboard port in C?

0

Share this post


Link to post
Share on other sites

lol, in my last post i was only jokin. My real answer is below :)

I dont know the exact code or how it works with the keyboard but Im pretty sure its still just basic Input/Output. you have to do something like

 keyboard = XXXXXXXXX

heh sry not much help, but also, i know it DOES NOT work with using some type of pre made keyboard buffer IF the keyboard did use one that you could work with.

And it will be different in NIX and Windows. In .net i would reccommend looking in System.Input or something to that syntax.

K.H.O.

0

Share this post


Link to post
Share on other sites

opps sry man, my brain farted

i think you should check out the ScanF() function, I think you would use that.

K.H.O.

0

Share this post


Link to post
Share on other sites

I know very little about programing, but i do remember planetsourcecode will show you how to do many things in different languages. I did a search for keystroke and C++ and this is what came up, hope it helps, else i would try searching the site yourself.

---------------

Imports System.Runtime.InteropServices

Public Class cKBHook

Public Event KeyPressed(ByVal KeyChar As Int32)

Delegate Function HookProc(ByVal nCode As Integer, ByVal wParam As IntPtr, _

ByVal lParam As IntPtr) As IntPtr

Declare Auto Function SetWindowsHookEx Lib "user32.dll" (ByVal idHook As Integer, _

ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal dwThreadId As Integer) As IntPtr

Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hhk As IntPtr) As Boolean

Declare Function CallNextHookEx Lib "user32.dll" (ByVal hhk As IntPtr, ByVal nCode As Integer, _

ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

Const WH_KEYBOARD_LL As Integer = 13

Shared hook As IntPtr

Public Function MyLLKbdProc(ByVal nCode As Integer, ByVal wParam As IntPtr, _

ByVal lParam As IntPtr) As IntPtr

RaiseEvent KeyPressed(Marshal.ReadInt32(lParam))

Return CallNextHookEx(hook, nCode, wParam, lParam)

End Function

Public Sub Listen()

Dim hp As HookProc = AddressOf MyLLKbdProc

hook = SetWindowsHookEx(WH_KEYBOARD_LL, hp, Marshal.GetHINSTANCE(GetType(cKBHook).Module), 0)

GC.KeepAlive(hp)

End Sub

Public Sub StopListening()

UnhookWindowsHookEx(hook)

End Sub

End Class

0

Share this post


Link to post
Share on other sites
I know very little about programing, but i do remember planetsourcecode will show you how to do many things in different languages.  I did a search for keystroke and C++ and this is what came up, hope it helps, else i would try searching the site yourself.

---------------

Imports System.Runtime.InteropServices

Public Class cKBHook

    Public Event KeyPressed(ByVal KeyChar As Int32)

    Delegate Function HookProc(ByVal nCode As Integer, ByVal wParam As IntPtr, _

    ByVal lParam As IntPtr) As IntPtr

    Declare Auto Function SetWindowsHookEx Lib "user32.dll" (ByVal idHook As Integer, _

    ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal dwThreadId As Integer) As IntPtr

    Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hhk As IntPtr) As Boolean

    Declare Function CallNextHookEx Lib "user32.dll" (ByVal hhk As IntPtr, ByVal nCode As Integer, _

    ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

    Const WH_KEYBOARD_LL As Integer = 13

    Shared hook As IntPtr

    Public Function MyLLKbdProc(ByVal nCode As Integer, ByVal wParam As IntPtr, _

                                ByVal lParam As IntPtr) As IntPtr

        RaiseEvent KeyPressed(Marshal.ReadInt32(lParam))

        Return CallNextHookEx(hook, nCode, wParam, lParam)

    End Function

    Public Sub Listen()

        Dim hp As HookProc = AddressOf MyLLKbdProc

        hook = SetWindowsHookEx(WH_KEYBOARD_LL, hp, Marshal.GetHINSTANCE(GetType(cKBHook).Module), 0)

        GC.KeepAlive(hp)

    End Sub

    Public Sub StopListening()

        UnhookWindowsHookEx(hook)

    End Sub

End Class

I believe that is VB. He was asking about C.

0

Share this post


Link to post
Share on other sites

In Windows, you need to monitor the keyboard buffer. I recommend you read the Win32 SDK support. It should list the correct functions and applications. Then, simply tell the program to output each keystroke into a file or wherever you want to put it. It's difficult to know exactly what you need without seeing the code.

0

Share this post


Link to post
Share on other sites

Google up hooker. Wait, no bad idea. Here, its an open source keylogger for Win systems.

0

Share this post


Link to post
Share on other sites
How many Phrack magazines are there? I see 63. Are there more than this? I want to start reading them all.

Issue 63 is hot off the press, and there aren't any more that I'm aware of.

0

Share this post


Link to post
Share on other sites
How many Phrack magazines are there? I see 63. Are there more than this? I want to start reading them all.

Issue 63 is hot off the press, and there aren't any more that I'm aware of.

well theres also Phrack High Council that isn't as popular. Thats only 2 issues i think though.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0