Proxy forwards and displays binary traffic
							Ursprung
							
								
									00cc5a0cad
								
							
						
					
					
						Commit
						037a9d69a4
					
				| @ -1,31 +1,48 @@ | |||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"io" | ||||||
|  | 	"os" | ||||||
| 	"proxy/cmd" | 	"proxy/cmd" | ||||||
|  | 	"unicode" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | // Start the two plugs and run two concurrent forward methods
 | ||||||
| func main() { | 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") | 	c2 := cmd.New("vde_plug", "/run/vde/sw_proxy.sock") | ||||||
| 	//c1 := cmd.New("ping", "localhost", "-c 10")
 | 	c1.Execute() | ||||||
| 	//c2 := cmd.New("nc", "google.com", "80")
 |  | ||||||
| 	//stdin, err := c2.StdinPipe()
 |  | ||||||
| 	//if err != nil {
 |  | ||||||
| 	//	log.Fatal(err)
 |  | ||||||
| 	//}
 |  | ||||||
| 	//c1.Execute()
 |  | ||||||
| 	c2.Execute() | 	c2.Execute() | ||||||
| 	//time.Sleep(time.Second)
 | 	go pipeForward(c1.OutReader, c2.InWriter, cmd.In) | ||||||
| 	//io.WriteString(stdin, "GET / HTTP/1.0\n\n")
 | 	go pipeForward(c2.OutReader, c1.InWriter, cmd.Out) | ||||||
| 	//time.Sleep(time.Second)
 | 	c1.WaitH() | ||||||
| 	//stdin.Close()
 |  | ||||||
| 	//c1.WaitH()
 |  | ||||||
| 	c2.WaitH() | 	c2.WaitH() | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| 	/* cmds := []*cmd.cmd{c1} | // Reads from an input and writes to and output,
 | ||||||
| 	for _, x := range cmds { | // do things to the content in between.
 | ||||||
| 		go func(cmd *exec.Cmd) { | // For now only output it in xxd format.
 | ||||||
| 		fmt.Printf(x.String()) | // Is meant to be run concurrently with "go pipeForward(...)"
 | ||||||
| 		}(cmd) | 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