Remote Desktop Viewer
Hello HF, this will be a fairly simple tutorial on how to code a Remote Desktop Viewer. You can use this to either make your own Team Viewer or implement it in a RAT for different purposes... it will be coded in reverse-connection and will use object serialization. I hope you will enjoy this
If you find any errors, please post and I will fix.Client (Sender)
-Create a windows form project in VS or VB 2010/2008 and call it RDV Client.
-Add 2 buttons and label them Connect and Stream respectively.
-Add a timer and set it to 1000.
-Right click the form and select "View Code"
Header Code required to shortcut your main code.Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Drawing
Imports System.Runtime.Serialization.Formatters.Binary
This goes right below "Public Class Form1". They are global TCPClient and Networkstream to allow connection and streaming.Dim client As New TcpClient
Dim nstream As NetworkStream
Now we make a function which returns the screenshot when called.Public Function Desktop() As Image
Dim bounds As Rectangle = Nothing
Dim screenshot As System.Drawing.Bitmap = Nothing
Dim graph As Graphics = Nothing
bounds = Screen.PrimaryScreen.Bounds
screenshot = New Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
Return screenshot
End Function
Image sending function through serialization. It will call the screenshot and send it using the networkstream.
Private Sub SendImage()
Dim bf As New BinaryFormatter
nstream = client.GetStream
bf.Serialize(nstream, Desktop())
End Sub
Double click the timer and type this in to call SendImage function.SendImage()
Double click the Connect button and add this. This will connect to localhost on port 8085.Try
client.Connect("127.0.0.1", 8085)
Catch ex As Exception
MsgBox("Failed to connect...")
End Try
Double click the Stream button and add this to start the timer.Timer1.start()
Conclusion: The client will connect to the server and stream images every 1 second. Done, now moving on to the server.
Server (Receiver)
-Create a windows form project in VS or VB 2010/2008 and call it RDV Server.
-Add a picturebox, fill dock it and change the sizemode to Stretch.
-Add 1 buttons and label it Listen. (if it dissapears try to bring it to front from the control panel)
-Right click the form and select "View Code"
Same imports as the last one.Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Drawing
Imports System.Runtime.Serialization.Formatters.BinaryGlobal Variables.. the only difference is that we make 2 threads now to prevent our window from lagging. One for listening and the other for receiving. Also we have the listening server.Dim client As New TcpClient
Dim server As New TcpListener(8085)
Dim nstream As NetworkStream
Dim listening As New Thread(AddressOf Listen)
Dim getImage As New Thread(AddressOf receiveImage)
Receive Image and deserialize function (opposite to SendImage)Private Sub receiveImage()
Dim bf As New BinaryFormatter
While client.Connected = True
nstream = client.GetStream
picturebox1.Image = bf.Deserialize(nstream)
End While
End Sub
Listening function to accept clients.Private Sub Listen()
While client.Connected = False
server.Start()
client = server.AcceptTcpClient
End While
getImage.Start()
End Sub
Double click the Listen button.listening.Start()
Conclusion: The server is ready to listen and accept any incoming connection. It will receive the images sent by the client.
How to use: Seriously? Open the client and server, click listen (server), then connect (client) and stream(client).
Note: If you wish to use this outside the local network, you might need to portforward the port you used and change the IP address.I work on this 2 days and finaly finish!