freeBuf
主站

分类

云安全 AI安全 开发安全 终端安全 数据安全 Web安全 基础安全 企业安全 关基安全 移动安全 系统安全 其他安全

特色

热点 工具 漏洞 人物志 活动 安全招聘 攻防演练 政策法规

点我创作

试试在FreeBuf发布您的第一篇文章 让安全圈留下您的足迹
我知道了

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

MemoryMapper:一款轻量级代码映射和进程注入工具
Alpha_h4ck 2020-07-02 21:50:03 274953

43434251-81f1bcb6-9440-11e8-8eaa-505914246ae6.png

MemoryMapper是一个轻量级代码库,在它的帮助下,广大研究人员可以直接使用进程注入和自注入的方式将本地程序集或托管程序集映射到内存之中。值得一提的是,该工具所提供的注入技术支持向正在运行中的进程注入程序集代码。除此之外,MemoryMapper不仅支持向内存中注入程序集代码,而且还提供了加密、解密和生成各种强加密性数据的功能。

工具依赖

1、 Windows 7 SP1或更高版本;

2、 .NET Framework 4.6.1;

功能介绍

-支持查看PE文件结构;

-从托管程序集和本机程序集读取资源;

-使用进程注入和自注入将本机程序集映射到内存中;

-使用进程注入和其他技术将托管程序集映射到内存中;

-获取任意文件大小的字节数组;

-加密和解密整个文件和原始字节;

-生成并验证文件和原始字节的校验和;

-使用SecureRandom对象生成强加密随机数据;

-捆绑了多种加密和散列算法

-加密:AES (ECB)、AES (CBC)、AES (CFB)、AES (OFB)、AES (CTR);

-哈希:MD5、RIPEMD160、SHA1、SHA256、SHA384、SHA512;

工具下载

广大研究人员可以使用下列命令将项目源码克隆至本地:

git clone https://github.com/jasondrawdy/MemoryMapper.git

工具使用

本地程序集注入

在这个演示样例中,我们将演示如何使用NativeLoader工具将本地程序集静态映射到内存中。该示例通过从磁盘读取文件的所有字节来加载该文件,然后将与字节相关联的PE(可移植可执行文件)直接注入进内存。使用本机加载程序和Amaterasu库中的动态代码编译,可以实现动态代码编译和向内存中注入所有代码。

using System

using System.IO;

using System.Reflection;

using MemoryMapper;

namespace Example

{

class Program

    {

static void Main(string[] args)

        {

            // Get the bytes of the file we want to load.

            var filePath = "FileToReadBytesOf";

            var fileBytes = File.ReadAllBytes(filePath);

            // Check if the assembly is managed or native.

            bool isManaged = false;

            try

            {

                // Note — this is one of the simplest variations of checking assemblies

                var assemblyName = AssemblyName.GetAssemblyName(filePath);

                if (assemblyName != null)

                    if (assemblyName.FullName != null)

                        isManaged = true;

            }

            catch { isManaged = false; }

            // Try loading the assembly if it's truly native.

            if (!isManaged

            {

                NativeLoader loader = new NativeLoader();

                if (loader.LoadAssembly(fileBytes))

                    Console.WriteLine("Assembly loaded successfully!");

                else

                    Console.WriteLine("Assembly could not be loaded.");

            }

            // Wait for user interaction.

            Console.Read();

        }

    }

}

托管程序集注入

这一个演示样例将演示如何通过读取托管程序集中的字节数据(或使用嵌入式字节数组),然后使用ManagedLoader工具将代码数据注入到当前正在运行的进程,并将托管程序集静态映射到内存之中。几乎所有托管程序集都可以使用本项目提供的ManagedLoader工具进行代码映射。

using System;

using System.IO;

using System.Reflection;

using MemoryMapper;

namespace Example

{

    class Program

    {

        static void Main(string[] args)

        {

            // Get the bytes of the file we want to load.

            var filePath = "FileToReadBytesOf";

            var fileBytes = File.ReadAllBytes(filePath);

            // Check if the assembly is managed or native.

            bool isManaged = false;

            try

            {

                // Note — this is one of the simplest variations of checking assemblies

                var assemblyName = AssemblyName.GetAssemblyName(filePath);

                if (assemblyName != null)

                    if (assemblyName.FullName != null)

                        isManaged = true;

            }

            catch { isManaged = false; }

            // Try loading the assembly if it's truly managed.

            if (isManaged)

            {

                // Set the name of a surrogate process - the process we'll inject into.

                var processName = "explorer.exe"; // Can also be the current process's name for self-injection.

                ManagedLoader loader = new ManagedLoader();

                if (loader.LoadAssembly(fileBytes, processName))

                    Console.WriteLine("Assembly loaded successfully!");

                else

                    Console.WriteLine("Assembly could not be loaded.");

            }

            // Wait for user interaction.

            Console.Read();

        }

    }

}

项目地址

MemoryMapper:【GitHub传送门

参考来源

jasondrawdy

# 系统安全 # 系统安全 # 注入工具
本文为 Alpha_h4ck 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
Alpha_h4ck LV.10
好好学习,天天向上
  • 2359 文章数
  • 1023 关注者
Tetragon:一款基于eBPF的运行时环境安全监控工具
2025-01-21
DroneXtract:一款针对无人机的网络安全数字取证工具
2025-01-21
CNAPPgoat:一款针对云环境的安全实践靶场
2025-01-21
文章目录