MCPcopy Create free account
hub / github.com/evilsocket/shellz / Exec

Method Exec

session/telnet.go:107–124  ·  view source on GitHub ↗
(cmd string)

Source from the content-addressed store, hash-verified

105}
106
107func (t *TelnetSession) Exec(cmd string) ([]byte, error) {
108 t.Lock()
109 defer t.Unlock()
110
111 cmd = fmt.Sprintf("(%s || echo) && echo PLACEHOLDER", cmd)
112 if _, err := t.doWrite([]byte(cmd + "\n")); err != nil {
113 return nil, fmt.Errorf("error while sending telnet command: %s", err)
114 }
115 t.doReadUntil(cmd)
116
117 if err, s := t.doReadUntil("PLACEHOLDER"); err != nil {
118 return nil, err
119 } else {
120 s = strings.Replace(s, "PLACEHOLDER", "", -1)
121 s = str.TrimLeft(s)
122 return []byte(s), nil
123 }
124}
125
126func (t *TelnetSession) Close() {
127 t.Lock()

Callers

nothing calls this directly

Calls 2

doWriteMethod · 0.95
doReadUntilMethod · 0.95

Tested by

no test coverage detected