Proxy forwards and displays binary traffic
Ursprung
00cc5a0cad
Commit
037a9d69a4
@ -1,31 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"proxy/cmd"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// Start the two plugs and run two concurrent forward methods
|
||||
func main() {
|
||||
//c1 := cmd.New("sh", "-c \"vde_plug /run/vde/sw_main.sock\"")
|
||||
c1 := cmd.New("vde_plug", "/run/vde/sw_main.sock")
|
||||
c2 := cmd.New("vde_plug", "/run/vde/sw_proxy.sock")
|
||||
//c1 := cmd.New("ping", "localhost", "-c 10")
|
||||
//c2 := cmd.New("nc", "google.com", "80")
|
||||
//stdin, err := c2.StdinPipe()
|
||||
//if err != nil {
|
||||
// log.Fatal(err)
|
||||
//}
|
||||
//c1.Execute()
|
||||
c1.Execute()
|
||||
c2.Execute()
|
||||
//time.Sleep(time.Second)
|
||||
//io.WriteString(stdin, "GET / HTTP/1.0\n\n")
|
||||
//time.Sleep(time.Second)
|
||||
//stdin.Close()
|
||||
//c1.WaitH()
|
||||
go pipeForward(c1.OutReader, c2.InWriter, cmd.In)
|
||||
go pipeForward(c2.OutReader, c1.InWriter, cmd.Out)
|
||||
c1.WaitH()
|
||||
c2.WaitH()
|
||||
}
|
||||
|
||||
/* cmds := []*cmd.cmd{c1}
|
||||
for _, x := range cmds {
|
||||
go func(cmd *exec.Cmd) {
|
||||
fmt.Printf(x.String())
|
||||
}(cmd)
|
||||
}*/
|
||||
// Reads from an input and writes to and output,
|
||||
// do things to the content in between.
|
||||
// For now only output it in xxd format.
|
||||
// Is meant to be run concurrently with "go pipeForward(...)"
|
||||
func pipeForward(reader io.Reader, writer io.Writer, prefix string) {
|
||||
i := 0
|
||||
for {
|
||||
bytes := make([]byte, 16)
|
||||
bytesReadable := make([]byte, 16)
|
||||
_, err := reader.Read(bytes)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
for i, ch := range bytes {
|
||||
if ch > unicode.MaxASCII || ch < '\u0020' {
|
||||
bytesReadable[i] = '\u002E'
|
||||
} else {
|
||||
bytesReadable[i] = ch
|
||||
}
|
||||
}
|
||||
xxdString := fmt.Sprintf("%s%08x: %04x %04x %04x %04x %04x %04x %04x %04x %s\n", prefix, i, bytes[0:1], bytes[2:3], bytes[4:5], bytes[6:7], bytes[8:9], bytes[10:11], bytes[12:13], bytes[14:15], bytesReadable)
|
||||
os.Stdout.WriteString(xxdString)
|
||||
writer.Write(bytes)
|
||||
i += 16
|
||||
}
|
||||
}
|
In neuem Issue referenzieren