Pages

Jumat, 11 November 2011

用VB学做“黑客”程序 Learn to do with VB "hacker" program

只要掌握了原理,你也能写出一个所谓的“黑客”程序。 Once you master the principles, you can write a so-called "hacker" program. 下面笔者带领大家用VB亲自编写一个远程控制程序。 Here I take you to use VB to write yourself a remote control program. 从而揭开它的神秘面纱。 To reveal its mystery.

一、所用控件 First, the use of control

在程序中将使用Winsock控件。 In the program will use the Winsock control. Winsock控件是一个ActiveX控件,使用TCP协议或UDP协议连接到远程计算机上并与之交换数据。 Winsock control is an ActiveX control, using TCP or UDP protocol to connect to the remote computer and exchange data. 和定时器控件一样,Winsock控件在运行时是不可见的。 And timer controls, like, Winsock control at run time is not visible. Winsock的工作原理是:客户端向服务器端发出连接请求,服务器端则不停地监听客户端的请求,当两者的协议沟通时,客户端和服务器端之间就建立了连接,这时客户端和服务器端就可以实现双向数据传输。 Winsock works is: the client for a connection request to the server, the server is constantly monitoring the client's request, when the communication protocol between the client and server-side connection is established between, then the client and server-side two-way data transmission can be achieved. 实际编程中,必须分别建立一个服务器端应用程序和一个客户端应用程序,两个应用程序中分别有自己的Winsock控件。 The actual programming, we must each create a server-side application and a client application, both applications have their Winsock control, respectively. 首先设置Winsock控件使用的协议,这里我们使用TCP协议。 First set the Winsock control protocol to use, here we use the TCP protocol. 现在,让我们开始用VB建立两个程序,一个是客户端程序myclient,另一个是服务器端程序myserver。 Now, let's start with VB to create two programs, one client myclient, the other is server-side program myserver.

二、编写客户端程序 Second, write the client program

首先来建客户端程序myclient。 First, to build client myclient. 在 myclient程序中建立一个窗体,加载Winsock控件,称为tcpclient,表示使用的是TCP协议,再加入两个文本框(text1和 text2),用来输入服务器的IP地址和端口号,然后建立一个按钮(cd1),用来建立连接,按下之后就可以对连接进行初始化了,代码如下: In myclient program to create a form, load the Winsock control, called tcpclient, that use the TCP protocol, then add two text boxes (text1 and text2), used to enter the server IP address and port number, and then establish a button (cd1), to establish the connection, you can click on the connection after initialization, the code is as follows:

private sub cd1_click() private sub cd1_click ()

tcpclient.romotehost=text1.text tcpclient.romotehost = text1.text

tcpclient.romoteport=val(text2.text)'端口号,缺省为1001 tcpclient.romoteport = val (text2.text) 'port number, default 1001

tcpclient.connect '调用connect方法,与指定IP地址的计算机进行连接 tcpclient.connect 'call the connect method, and specify the IP address of the computer to connect

cd1.enabled=false cd1.enabled = false

end sub end sub

连接之后就是如何处理所收到的数据的问题了。 After the connection is how to deal with the problem of data received. 客户端和服务器端建立连接后,如果有任何一端接收到新的数据,就会触发该端winsock控件的dataarrival事件,在响应这个事件时,可以使用getdata方法获得发送来的数据。 Client and server establish a connection, if there is any new data is received at one end, it will trigger the side winsock control dataarrival event, in response to this event, you can use the getdata sent to the data obtained. 比如可以在tcpclient的dataarrival事件中编写代码如下: For example you can tcpclient the dataarrival event code is as follows:

private sub tcpclient_dataarrival(byval bytestotal as long) private sub tcpclient_dataarrival (byval bytestotal as long)

dim x as string dim x as string

tcpclient.getdata x '使用getdata获得发送来的数据 tcpclient.getdata x 'using getdata be sent to the data

....... .......

End sub End sub

后面的省略部分表示对接收到的数据进行的具体处理,读者可以根据实际情况编写。 Omitted part of the back of the received data that the specific treatment, the reader can write the actual situation.

三、编写服务器端程序 Third, write server-side program

先建立一个窗体,加载Winsock控件,名称为tcpserver。 First create a form, load the Winsock control, name tcpserver. 另外在窗体上加入一个文本框text1用来显示客户机的IP地址和客户机发送过来的数据信息。 Also in the form to add a text box text1 used to display the IP address of the client and the client to send over the data.

当客户端程序运行时,在客户端程序按下连接按钮后,客户端向服务器端程序请求连接,这时服务器端的connectionrequest事件被触发,所以服务器端程序要解决连接问题,可以使用connectionrequest事件完成此功能。 When the client program runs, the client program press the Connect button, the client application requests a connection to the server, then server-side connectionrequest event is triggered, the server-side programs to solve connection problems, you can use to complete this event connectionrequest function. 代码如下: Code is as follows:

'在窗体的load事件中对tcpserver控件进行初始化 'In the form load event to initialize the control of tcpserver

private sub form_load() private sub form_load ()

tcpserver.localport=1001 tcpserver.localport = 1001

tcpserver.listen '把服务器置于监听检测状态 tcpserver.listen 'placed in the server status monitor detects

end sub end sub

'服务器端接收到客户端的连接请求,首先检查当前状态是否处于连接关闭状态 'Server receives a client connection request, it first checks whether the current state in connection off

Private sub tcpclient_connectionrequest(Byval requestID as long) Private sub tcpclient_connectionrequest (Byval requestID as long)

If tcpserver.state<>sckclosed then '检查控件的state属性是否为关闭 If tcpserver.state <> sckclosed then 'check control of state property is close

Tcpserver.close ' Tcpserver.close '

Tcpserver.accept requestID ' Tcpserver.accept requestID '

End if End if

End sub End sub

现在我们在服务器端程序tcpserver的dataarrival事件中添加以下代码,以便让服务器端程序可以接收客户机端的指令,并运行相应的程序。 Now we are on the server side program tcpserver's dataarrival event add the following code to the server-side client-side application can receive instructions and run the corresponding program.

四、测试远程控制程序 Fourth, test the remote control program

现在,你就可以将这两个程序分别运行于两台使用TCP/IP协议联网的机器了。 Now, you can run these two programs were used in the two TCP / IP protocol networked machine. 在客户机端你按下连接按钮,再输入“c: mmand.com”,可以看到在服务器端立刻打开一个DOS窗口,设想一下,如果它运行一些破坏性的命令会发生什么事情? On the client side you press the Connect button, and enter "c: mmand.com", you can see on the server side immediately open a DOS window, just imagine, if it runs some of the destructive command what happens? 这就是一个最基本的远程控制程序。 This is a basic remote control program. 当然,真正的黑客程序要复杂得多,但基本原理是相同的。 Of course, the real hack is much more complex, but the basic principle is the same. 现在你该恍然大悟了吧? Now you suddenly realize it?

Tidak ada komentar:

Posting Komentar