Need
.Net Framework 4.0 (to run .exe)
Visual C# (to edit code / compile)
This isn't really a remote administration tool, but with a few adjustments you can quickly make it into one. This is really just a basic chat client all in one. It uses TCP to communicate back and forth.
The server and client are on the same form. I made it that way so that it was easier to understand. It is very well organized and few messy parts that I dislike very much.
What is a Remote Administration Tool (RAT)?
Remote Administration Tool (RAT)
A Remote Administration Tool (known more commonly on the Internet as a RAT) is used to remotely connect and manage a single or multiple computers with a variety of tools.
Server & Client Coding
TCP Modules: HerePHP Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace HowToMakeARat
{
public partial class frmMain : Form
{
#region Declarings
TCPServer Server;
TCPClient Client;
//Declared them up here so we can use them through out the program.
#endregion
public frmMain()
{
InitializeComponent();
}
#region TextBoxes
private void txtSLog_TextChanged(object sender, EventArgs e)
{
//Auto Scroll TextBox - MESSY. D<
txtSLog.Select(txtSLog.TextLength, 0);
txtSLog.ScrollToCaret();
txtSLog.Refresh();
}
private void txtCLog_TextChanged(object sender, EventArgs e)
{
//Auto Scroll TextBox - MESSY. D<
txtCLog.Select(txtCLog.TextLength, 0);
txtCLog.ScrollToCaret();
txtCLog.Refresh();
}
#endregion
#region Server
private void btnListen_Click(object sender, EventArgs e)
{
Thread sThread = new Thread(new ThreadStart(delegate { ListenHandler(Int32.Parse(txtPort.Text)); }));
if (btnListen.Text == "Listen")
{
sThread.Start();
btnListen.Text = "Stop";
}
else
{
sThread.Abort();
btnListen.Text = "Listen";
}
}
private void ListenHandler(Int32 Port)
{
Server = new TCPServer(Port); //Creates a server on the Port.
while (Server.Connected() == false)
{
Server.Listen(); //Waits for a connection on the given port.
ServerStatus("Status: Listening...");
if (Server.Connected() == true)
{
ServerStatus("Status: Connected!");
ServerLog(DateTime.Now + " - Connected!");
while (Server.Connected() == true)
{
String Data = Server.GetData(); //Get Data being sent to server.
//If Data is null then nothing has been received.
if (Data != null)
{
ServerLog("Client Said: " + Data);
}
}
ServerLog(DateTime.Now + " - Disconnected!");
ServerStatus("Status: Listening...");
}
}
}
private void btnSend_Click(object sender, EventArgs e)
{
if (Server.Connected() == true)
{
Server.SendData(txtSMessage.Text);
}
}
#endregion
#region Client
private void btnConnect_Click(object sender, EventArgs e)
{
Thread cThread = new Thread(new ThreadStart(delegate { ConnectHandler(txtIP.Text, Int32.Parse(txtCPort.Text)); }));
Client = new TCPClient(); //Creates a new Client.
if (btnConnect.Text == "Connect")
{
cThread.Start();
}
else
{
cThread.Abort();
btnConnect.Text = "Connect";
lblCStatus.Text = "Offline...";
}
}
private void ConnectHandler(String IP, Int32 Port)
{
if (Client.Connect(txtIP.Text, Int32.Parse(txtCPort.Text)) == true)
{
ClientStatus("Status: Connected!");
ClientLog(DateTime.Now + " - Connected!");
ClientButton("Close");
while (Client.Connected() == true)
{
String Data = Client.GetData();
if (Data != null)
{
ClientLog("Server Said: " + Data);
}
}
}
}
private void btnCSend_Click(object sender, EventArgs e)
{
if (Client.Connected() == true)
{
Client.SendData(txtCMessage.Text);
}
}
#endregion
#region Invokes
private void ServerStatus(String Text)
{
Invoke(new MethodInvoker(
delegate { lblSStatus.Text = Text; }
));
}
private void ClientStatus(String Text)
{
Invoke(new MethodInvoker(
delegate { lblCStatus.Text = Text; }
));
}
private void ClientButton(String Text)
{
Invoke(new MethodInvoker(
delegate { btnConnect.Text = Text; }
));
}
private void ServerLog(String Text)
{
Invoke(new MethodInvoker(
delegate { txtSLog.Text += Text + "\r\n"; }
));
}
private void ClientLog(String Text)
{
Invoke(new MethodInvoker(
delegate { txtCLog.Text += Text + "\r\n"; }
));
}
#endregion
#region Other
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
//Let's force close the application to close all the threads
//So it doesn't run in the background...
Process.GetCurrentProcess().Kill();
}
#endregion
}
}
Download Source:
Here
OR
Here
This is for educational purposes only.
Keep in mind that if you plan on making a RAT, and you plan on running the Server, you need to be port forwarded so other people can connect to you.
Results 1 to 1 of 1
- 29 Nov. 2010 04:31am #1
[C#] SIMPLE Remote Administration Tool MULTI THREADED (TCP)