Skip to content

Commit

Permalink
Added TCP proxy to proxy to different site
Browse files Browse the repository at this point in the history
  • Loading branch information
vanshaj committed Jun 3, 2021
1 parent 5f8b6f4 commit ec9d674
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions blackhatgo/chapter2/TcpProxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"io"
"log"
"net"
)

func handle(conn net.Conn) {
destConn, err := net.Dial("tcp", "scanme.nmap.org:80")
if err != nil {
log.Fatalln("Unable to connect to scan me ", err)
}
go func() {
_, err = io.Copy(destConn, conn)
if err != nil {
log.Fatalln("Unable to copy to dest writer ", err)
}
}()

_, err = io.Copy(conn, destConn)
if err != nil {
log.Fatalln("unable to copy response to source writer ", err)
}
}

func main() {
listener, err := net.Listen("tcp", ":9091")
if err != nil {
log.Fatalln("Unable to listen ", err)
}
for {
conn, err2 := listener.Accept()
if err2 != nil {
log.Fatalln("Unable to accept ", err2)
}
go handle(conn)
}
}

0 comments on commit ec9d674

Please sign in to comment.