简体   繁体   English

客户端监视键盘记录器问题

[英]Client Monitoring keylogger problem

First of all, the keylogger that i am developing is not at all for offensive and destructive purposes. 首先,我正在开发的键盘记录器根本不是出于进攻和破坏目的。 :) :)

I am developing a client monitoring application in C#.NET. 我正在C#.NET中开发客户端监视应用程序。 Keylogging is one of the features in my application. 键盘记录是我应用程序中的功能之一。 Though i have developed the code for the keylogger, i have not been able to implement it properly in my application. 尽管我已经为键盘记录器开发了代码,但是我无法在我的应用程序中正确实现它。

There are two projects in my solution. 我的解决方案中有两个项目。 The UserInterface - for server side. UserInterface-用于服务器端。 The Tracker - for client side PCs. Tracker-用于客户端PC。 The keylogging module Keylogger is in the Tracker project. 键盘记录模块Keylogger在Tracker项目中。

I have used the helper classes for socket programming - TcpClient, TcpListener and NetworkStream to help them out. 我已经使用套接字类的帮助程序类-TcpClient,TcpListener和NetworkStream来帮助它们。

Also, i am using asynchronous mode for communication. 另外,我正在使用异步模式进行通信。

I am posting the part of code with which i am facing the problem : 我正在发布我面临问题的代码部分:

//This code resides on the server-side monitoring interface.When //the administrator hits a btnKeyLog button, a 

message //"StartKeyLog" is sent to the respective client, and the keylogging //is handled on the client.

private void btnKeyLog_Click ( object sender, EventArgs e ) { messageBuffer = new byte[100]; 私有无效btnKeyLog_Click(对象发送者,EventArgs e){messageBuffer =新字节[100];

    if ( btnKeyLog1.Text == "Start Keylogging" )
    {
        btnKeyLog1.Text = "Stop Keylogging";
        message = "StartKeyLog";

        messageBuffer = Encoding.ASCII.GetBytes ( message );
        try
        {
                //begin writing on the stream.
        clientConnections[0].networkStream.BeginWrite (messageBuffer, 0, messageBuffer.Length, new 

AsyncCallback ( onDataWrite ), null );
        }
        catch ( Exception exc )
        {
            MessageBox.Show ( exc.Message + exc.StackTrace );
        }
    }
    else
    {
        btnKeyLog1.Text = "Start Keylogging";
        message = "StopKeyLog";

        messageBuffer = Encoding.ASCII.GetBytes ( message );
        try
        {
        clientConnections[0].networkStream.BeginWrite ( messageBuffer, 0, messageBuffer.Length, new 

AsyncCallback ( onDataWrite ), null );
        }
        catch ( Exception exc )
        {
            MessageBox.Show ( exc.Message + exc.StackTrace );
        }
    }
}

Now, the client-side code : 现在,客户端代码:

public void onDataReceived ( IAsyncResult ar )
{
    int nBytesRead = 0;
    try
    {
        nBytesRead = clientConnection.networkStream.EndRead ( ar );
    }
    catch ( Exception exc )
    {
        MessageBox.Show ( exc.Message + exc.StackTrace );
    }
    message = Encoding.ASCII.GetString ( messageBuffer,0, nBytesRead);
    switch (message)
    {
        case "StartKeyLog" :
            MessageBox.Show ( "Keylogger started." );
                       //the following static method wraps the Win32 //implementation of SetWindowsHookEx - all given in Keylogger //module
            KeyboardHook.installHook ( );
                       //after this method is called, the hook is //actually installed; the callback function KeyboardHookProc is also //called.        

    Here, keylogger seems to be working fine, except that the //system slows down considerably when i type keystrokes.
        break;

        case "StopKeyLog":
            MessageBox.Show ( "Keylogger stopped." );
                        // the following method releases the hook
            KeyboardHook.releaseHook ( );
        break;
    }

    try
    {
        messageBuffer = new byte[100];
        clientConnection.networkStream.BeginRead ( messageBuffer, 0, messageBuffer.Length, new AsyncCallback ( onDataReceived ), null );
    }
    catch ( Exception exc )
    {
        MessageBox.Show ( exc.Message + exc.StackTrace );
    }
    //MessageBox.Show ( "Stop" );
//as soon as this function ends, however, the callback function of //the keyboard hook stops being called; keystrokes are not //processed.
//the keystrokes are caught until this function the control is in this //function. i assume that it has to do something with the thread.
}

I am trying to explain the situation here. 我想在这里解释情况。 To start keylogging, the server UI would send a message "StartKeyLog" to the client. 要开始键盘记录,服务器UI将向客户端发送消息“ StartKeyLog”。 On receiving the message, the client will process it in the callback function "onDataReceived".In this function, the message is processed and the 客户端收到消息后,将在回调函数“ onDataReceived”中对其进行处理。在此函数中,消息将被处理,

installHook() method is called, which would install the hook. 将调用installHook()方法,该方法将安装该挂钩。

When i ran the application, the hook got installed; 当我运行应用程序时,钩子已安装; also, the KeyboardHookProc() callback got called properly, and the keystrokes were processed. 同样,正确调用了KeyboardHookProc()回调,并处理了击键。 But this 但是这个

was the case only till the onDataReceived callback method was alive. 只有在onDataReceived回调方法有效之前,情况才如此。 As soon as the that method ended, the KeyboardHookProc() stopped getting called; 该方法结束后,KeyboardHookProc()停止调用。 keys

were no longer processed, as if the hook was never installed. 不再处理,好像从未安装过该挂钩。

Another problem was that after the hook got installed, the system got considerably slow when i hit any key. 另一个问题是,安装了挂钩之后,当我按任意键时,系统就会变得相当慢。

My assumption is that both the things have something to do with the threading that happens here. 我的假设是,这两种情况都与此处发生的线程有关。 But, i am not able to get the exact problem. 但是,我无法得到确切的问题。 I have tried my best to explain the situation.Still, any questions are welcome. 我尽力解释了这种情况。欢迎您提出任何问题。 Could anyone provide me with the solution?? 谁能为我提供解决方案?

您应该添加您的KeyboardHook的代码。

well, i have managed to solve my problem. 好吧,我设法解决了我的问题。 The problem was that i was setting the hook on a thread that the main thread of my application had invoked. 问题是我在应用程序的主线程调用的线程上设置了钩子。 Infact, i had started that thread just to install the hook. 实际上,我只是为了安装钩子而启动了该线程。 I just restructured my code so that the hook was installed on the main thread. 我只是重组了代码,以便将钩子安装在主线程上。 It solved out the whole problem. 它解决了整个问题。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM