github.com/iDigitalFlame/xmt@v0.5.4/c2/task/v_evade.go (about) 1 //go:build !implant 2 // +build !implant 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package task 21 22 import ( 23 "github.com/iDigitalFlame/xmt/com" 24 "github.com/iDigitalFlame/xmt/device/winapi" 25 ) 26 27 // FuncUnmapAll returns a syscall function unmap Packet. This can be used to instruct 28 // the client to unmap all of the re-mapped ntdll.dll functions to their original 29 // addresses. 30 // 31 // This function only returns an error if it occurred during unmapping. 32 // 33 // Always returns 'ErrNoWindows' on non-Windows devices. Clients must have the 34 // "funcmap" capability or they will return nil. 35 // 36 // C2 Details: 37 // 38 // ID: TvFuncMap 39 // 40 // Input: 41 // uint8 // Always 2 for this 42 // Output: 43 // <none> 44 func FuncUnmapAll() *com.Packet { 45 n := &com.Packet{ID: TvFuncMap} 46 n.WriteUint8(taskFuncMapUnmapAll) 47 return n 48 } 49 50 // Evade returns a client Evasion Packet. This can be used to instruct the client 51 // perform evasion functions dependent on the supplied bitmask value. 52 // 53 // Some evasion methods include zero-ing out function calls and disabling Debugger 54 // view of functions. 55 // 56 // This will return an error if it fails. 57 // 58 // Always returns 'ErrNoWindows' on non-Windows devices. 59 // 60 // C2 Details: 61 // 62 // ID: TvEvade 63 // 64 // Input: 65 // uint8 // Evasion Flags 66 // Output: 67 // <none> 68 func Evade(f uint8) *com.Packet { 69 n := &com.Packet{ID: TvEvade} 70 n.WriteUint8(f) 71 return n 72 } 73 74 // FuncRemapList returns a syscall function mapping list Packet. This can be used to 75 // instruct the client to return details of all of the re-mapped ntdll.dll functions. 76 // 77 // The result will be an array of FuncEntries that will indicate the new and original 78 // memory addresses of the function the represent. 79 // 80 // Always returns 'ErrNoWindows' on non-Windows devices. Clients must have the 81 // "funcmap" capability or they will return nil. 82 // 83 // C2 Details: 84 // 85 // ID: TvFuncMapList 86 // 87 // Input: 88 // <none> 89 // Output: 90 // uint32 // Count 91 // []FuncEntry { // List of open Windows 92 // uint32 // Function hash 93 // uint64 // Function original address 94 // uint64 // Function swapped address 95 // } 96 func FuncRemapList() *com.Packet { 97 return &com.Packet{ID: TvFuncMapList} 98 } 99 100 // FuncUnmap returns a syscall function unmap Packet. This can be used to instruct 101 // the client to unmap the re-mapped ntdll.dll function name to it's original address. 102 // 103 // This function only returns an error if it occurred during unmapping. 104 // 105 // Always returns 'ErrNoWindows' on non-Windows devices. Clients must have the 106 // "funcmap" capability or they will return nil. 107 // 108 // C2 Details: 109 // 110 // ID: TvFuncMap 111 // 112 // Input: 113 // uint8 // Always 1 for this 114 // uint32 // FNV Hash of the function name 115 // Output: 116 // <none> 117 func FuncUnmap(name string) *com.Packet { 118 n := &com.Packet{ID: TvFuncMap} 119 n.WriteUint8(taskFuncMapUnmap) 120 n.WriteUint32(winapi.FnvHash(name)) 121 return n 122 } 123 124 // CheckDLLFile returns a DLL integrity verification Packet. This can be used to 125 // instruct the client to check the in-memory contents of the DLL name or file 126 // path provided to ensure it matches "known-good" values. 127 // 128 // This function version will read in the DLL data from the client disk and will 129 // verify the entire executable region. 130 // 131 // DLL base names will be expanded on the client to full paths not if already full 132 // path names. (Unless it is a known DLL name). 133 // 134 // The clients returns true if the DLL is considered valid/unhooked. 135 // 136 // Always returns 'ErrNoWindows' on non-Windows devices. 137 // 138 // C2 Details: 139 // 140 // ID: TvCheck 141 // 142 // Input: 143 // string // DLL Name/Path 144 // string // Empty for this function 145 // uint32 // Zero for this function 146 // []byte // Empty for this function 147 // Output: 148 // bool // True if DLL is clean, false if it is tampered with 149 func CheckDLLFile(dll string) *com.Packet { 150 n := &com.Packet{ID: TvCheck} 151 n.WriteString(dll) 152 n.WriteUint32(0) 153 n.WriteUint16(0) 154 return n 155 } 156 157 // PatchDLLFile returns a DLL patching Packet. This can be used to instruct the 158 // client to overrite the in-memory contents of the DLL name or file path 159 // provided to ensure it has "known-good" values. 160 // 161 // This function version will read in the DLL data from the client disk and will 162 // overwite the entire executable region. 163 // 164 // DLL base names will be expanded on the client to full paths not if already full 165 // path names. (Unless it is a known DLL name). 166 // 167 // Always returns 'ErrNoWindows' on non-Windows devices. 168 // 169 // C2 Details: 170 // 171 // ID: TvPatch 172 // 173 // Input: 174 // string // DLL Name/Path 175 // string // Empty for this function 176 // uint32 // Zero for this function 177 // []byte // Empty for this function 178 // Output: 179 // <none> 180 func PatchDLLFile(dll string) *com.Packet { 181 n := &com.Packet{ID: TvPatch} 182 n.WriteString(dll) 183 n.WriteUint32(0) 184 n.WriteUint16(0) 185 return n 186 } 187 188 // FuncRemap returns a syscall function mapping Packet. This can be used to instruct 189 // the client to upload the bytes to be re-mapped to a new memory address that 190 // can be used to override the supplied ntdll.dll function name. 191 // 192 // This function only returns an error if it occurred during mapping. 193 // 194 // Always returns 'ErrNoWindows' on non-Windows devices. Clients must have the 195 // "funcmap" capability or they will return EINVAL. 196 // 197 // C2 Details: 198 // 199 // ID: TvFuncMap 200 // 201 // Input: 202 // uint8 // Always 0 for this 203 // uint32 // FNV Hash of the function name 204 // []byte // Function bytes to write into memory 205 // Output: 206 // <none> 207 func FuncRemap(name string, b []byte) *com.Packet { 208 n := &com.Packet{ID: TvFuncMap} 209 n.WriteUint8(taskFuncMapMap) 210 n.WriteUint32(winapi.FnvHash(name)) 211 n.WriteBytes(b) 212 return n 213 } 214 215 // CheckFunction returns a DLL function integrity verification Packet. This can 216 // be used to instruct the client to check the in-memory contents of the DLL name 217 // or file path provided with the supplied function name to ensure it matches 218 // "known-good" values. 219 // 220 // This function version will check the function base address against the supplied 221 // bytes. If the bytes supplied are nil/empty, this will do a simple long JMP/CALL 222 // Assembly check instead. 223 // 224 // DLL base names will be expanded on the client to full paths not if already full 225 // path names. (Unless it is a known DLL name). 226 // 227 // The clients returns true if the DLL function is considered valid/unhooked. 228 // 229 // Always returns 'ErrNoWindows' on non-Windows devices. 230 // 231 // C2 Details: 232 // 233 // ID: TvCheck 234 // 235 // Input: 236 // string // DLL Name/Path 237 // string // Function name 238 // uint32 // Zero for this function 239 // []byte // Function bytes to check against 240 // Output: 241 // bool // True if DLL is clean, false if it is tampered with 242 func CheckFunction(dll, name string, b []byte) *com.Packet { 243 n := &com.Packet{ID: TvCheck} 244 n.WriteString(dll) 245 n.WriteString(name) 246 n.WriteUint32(0) 247 n.WriteBytes(b) 248 return n 249 } 250 251 // PatchFunction returns a DLL patching Packet. This can be used to instruct the 252 // client to overrite the in-memory contents of the DLL name or file path 253 // provided with the supplied function name to ensure it has "known-good" values. 254 // 255 // This function version will overwite the function base address against the supplied 256 // bytes. If the bytes supplied are nil/empty, this will pull the bytes for the 257 // function from the local DLL source. 258 // 259 // DLL base names will be expanded on the client to full paths not if already full 260 // path names. (Unless it is a known DLL name). 261 // 262 // Always returns 'ErrNoWindows' on non-Windows devices. 263 // 264 // C2 Details: 265 // 266 // ID: TvPatch 267 // 268 // Input: 269 // string // DLL Name/Path 270 // string // Function name 271 // uint32 // Zero for this function 272 // []byte // Function bytes to check against 273 // Output: 274 // <none> 275 func PatchFunction(dll, name string, b []byte) *com.Packet { 276 n := &com.Packet{ID: TvPatch} 277 n.WriteString(dll) 278 n.WriteString(name) 279 n.WriteUint32(0) 280 n.WriteBytes(b) 281 return n 282 } 283 284 // CheckDLL returns a DLL integrity verification Packet. This can be used to 285 // instruct the client to check the in-memory contents of the DLL name or file 286 // path provided to ensure it matches "known-good" values. 287 // 288 // This function version will check the DLL contents against the supplied bytes 289 // and starting address. The 'winapi.ExtractDLLBase' can suppply these values. 290 // If the byte array is nil/empty, this will instead act like the 'CheckDLLFile' 291 // function and read from disk. 292 // 293 // DLL base names will be expanded on the client to full paths not if already full 294 // path names. (Unless it is a known DLL name). 295 // 296 // The clients returns true if the DLL is considered valid/unhooked. 297 // 298 // Always returns 'ErrNoWindows' on non-Windows devices. 299 // 300 // C2 Details: 301 // 302 // ID: TvCheck 303 // 304 // Input: 305 // string // DLL Name/Path 306 // string // Empty for this function 307 // uint32 // Zero for this function 308 // []byte // Empty for this function 309 // Output: 310 // bool // True if DLL is clean, false if it is tampered with 311 func CheckDLL(dll string, addr uint32, b []byte) *com.Packet { 312 n := &com.Packet{ID: TvCheck} 313 n.WriteString(dll) 314 n.WriteUint8(0) 315 n.WriteUint32(addr) 316 n.WriteBytes(b) 317 return n 318 } 319 320 // PatchDLL returns a DLL patching Packet. This can be used to instruct the 321 // client to overrite the in-memory contents of the DLL name or file path 322 // provided to ensure it has "known-good" values. 323 // 324 // This function version will overwrite the DLL contents against the supplied bytes 325 // and starting address. The 'winapi.ExtractDLLBase' can suppply these values. 326 // If the byte array is nil/empty, this will instead act like the 'PatchDLLFile' 327 // function and read from disk. 328 // 329 // DLL base names will be expanded on the client to full paths not if already full 330 // path names. (Unless it is a known DLL name). 331 // 332 // Always returns 'ErrNoWindows' on non-Windows devices. 333 // 334 // C2 Details: 335 // 336 // ID: TvPatch 337 // 338 // Input: 339 // string // DLL Name/Path 340 // string // Empty for this function 341 // uint32 // Zero for this function 342 // []byte // Empty for this function 343 // Output: 344 // <none> 345 func PatchDLL(dll string, addr uint32, b []byte) *com.Packet { 346 n := &com.Packet{ID: TvPatch} 347 n.WriteString(dll) 348 n.WriteUint8(0) 349 n.WriteUint32(addr) 350 n.WriteBytes(b) 351 return n 352 } 353 354 // CheckFunctionFile returns a DLL function integrity verification Packet. This can 355 // be used to instruct the client to check the in-memory contents of the DLL name 356 // or file path provided with the supplied function name to ensure it matches 357 // "known-good" values. 358 // 359 // This function version will check the function base address against the supplied 360 // bytes. If the bytes supplied are nil/empty, this will pull the bytes for the 361 // function from the local DLL source. 362 // 363 // DLL base names will be expanded on the client to full paths not if already full 364 // path names. (Unless it is a known DLL name). 365 // 366 // The clients returns true if the DLL function is considered valid/unhooked. 367 // 368 // Always returns 'ErrNoWindows' on non-Windows devices. 369 // 370 // C2 Details: 371 // 372 // ID: TvCheck 373 // 374 // Input: 375 // string // DLL Name/Path 376 // string // Function name 377 // uint32 // Zero for this function 378 // []byte // Function bytes to check against 379 // Output: 380 // bool // True if DLL is clean, false if it is tampered with 381 func CheckFunctionFile(dll, name string, b []byte) *com.Packet { 382 n := &com.Packet{ID: TvCheck} 383 n.WriteString(dll) 384 n.WriteString(name) 385 n.WriteUint32(1) 386 n.WriteBytes(b) 387 return n 388 }