Skip to content

Commit

Permalink
update log format
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzc committed Jan 11, 2022
1 parent 3fa45b3 commit d9b10eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
5 changes: 5 additions & 0 deletions cmd/spoof-dpi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os/signal"
"syscall"

"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/xvzc/SpoofDPI/doh"
"github.com/xvzc/SpoofDPI/proxy"
Expand All @@ -22,6 +23,10 @@ func main() {
log.SetLevel(log.InfoLevel)
}

log.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})

util.PrintWelcome(port, dns, debug)

if err := util.SetOsProxy(port); err != nil {
Expand Down
24 changes: 12 additions & 12 deletions net/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
// Create connection to server
rConn, err := Dial("tcp", ip+":80")
if err != nil {
log.Debug(err)
log.Debug("[HTTPS] ", err)
return
}
defer rConn.Close()
Expand All @@ -98,14 +98,14 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
ip, err := doh.Lookup(p.Domain())
if err != nil {
log.Debug("[HTTPS] Error looking up for domain: ", err)
log.Debug("[HTTPS] Error looking up for domain: ", p.Domain(), " ", err)
}
log.Debug("[HTTPS] Found ip over HTTPS: ", ip)

// Create a connection to the requested server
rConn, err := Dial("tcp", ip+":443")
if err != nil {
log.Debug(err)
log.Debug("[HTTPS] ", err)
return
}
defer rConn.Close()
Expand All @@ -122,10 +122,10 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
clientHello, err := lConn.ReadBytes()
if err != nil {
log.Debug("[HTTPS] Error reading client hello: ", err)
log.Debug("Closing connection: ", lConn.RemoteAddr())
log.Debug("[HTTPS] Closing connection: ", lConn.RemoteAddr())
}

log.Debug(lConn.RemoteAddr(), "[HTTPS] Client sent hello: ", len(clientHello), "bytes")
log.Debug("[HTTPS] Client "+lConn.RemoteAddr().String()+" sent hello: ", len(clientHello), "bytes")

// Generate a go routine that reads from the server
go rConn.Serve(lConn, "HTTPS")
Expand All @@ -146,17 +146,17 @@ func (from *Conn) Serve(to *Conn, proto string) {
for {
buf, err := from.ReadBytes()
if err != nil {
log.Debug("["+proto+"]"+" Error reading from ", from.RemoteAddr())
log.Debug("["+proto+"]", err)
log.Debug("[" + proto + "]" + " Exiting Serve() method. ")
log.Debug("["+proto+"] "+"Error reading from ", from.RemoteAddr())
log.Debug("["+proto+"] ", err)
log.Debug("[" + proto + "] " + "Exiting Serve() method. ")
break
}
log.Debug(from.RemoteAddr(), " sent data: ", len(buf), "bytes")
log.Debug("["+proto+"] ", from.RemoteAddr(), " sent data: ", len(buf), "bytes")

if _, err := to.Write(buf); err != nil {
log.Debug("["+proto+"]"+"Error Writing to ", to.RemoteAddr())
log.Debug("["+proto+"]", err)
log.Debug("[" + proto + "]" + " Exiting Serve() method. ")
log.Debug("["+proto+"] "+"Error Writing to ", to.RemoteAddr())
log.Debug("["+proto+"] ", err)
log.Debug("[" + proto + "] " + "Exiting Serve() method. ")
break
}
}
Expand Down
4 changes: 2 additions & 2 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func (p *Proxy) Start() {
}

if pkt.IsConnectMethod() {
log.Debug("HTTPS Requested")
log.Debug("[HTTPS] Start")
conn.HandleHttps(pkt)
} else {
log.Debug("HTTP Requested.")
log.Debug("[HTTP] Start")
conn.HandleHttp(pkt)
}
}()
Expand Down

0 comments on commit d9b10eb

Please sign in to comment.