SpoofDPI/proxy/http.go

54 lines
1.3 KiB
Go
Raw Normal View History

2024-07-22 04:49:18 +00:00
package proxy
import (
2024-07-22 10:59:11 +00:00
"net"
"strconv"
2024-07-22 04:49:18 +00:00
log "github.com/sirupsen/logrus"
2024-07-22 10:59:11 +00:00
2024-07-22 04:49:18 +00:00
"github.com/xvzc/SpoofDPI/packet"
)
2024-07-22 11:58:30 +00:00
func (pxy *Proxy) handleHttp(lConn *net.TCPConn, pkt *packet.HttpPacket, ip string) {
2024-07-22 04:49:18 +00:00
pkt.Tidy()
2024-07-22 10:59:11 +00:00
// Create a connection to the requested server
var port int = 80
var err error
2024-07-22 04:49:18 +00:00
if pkt.Port() != "" {
2024-07-22 10:59:11 +00:00
port, err = strconv.Atoi(pkt.Port())
if err != nil {
2024-07-22 11:24:35 +00:00
log.Debug("[HTTP] Error while parsing port for ", pkt.Domain(), " aborting..")
2024-07-22 10:59:11 +00:00
}
2024-07-22 04:49:18 +00:00
}
2024-07-22 10:59:11 +00:00
rConn, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: net.ParseIP(ip), Port: port})
2024-07-22 04:49:18 +00:00
if err != nil {
2024-07-22 10:59:11 +00:00
lConn.Close()
2024-07-22 04:49:18 +00:00
log.Debug("[HTTP] ", err)
return
}
defer func() {
lConn.Close()
log.Debug("[HTTP] Closing client Connection.. ", lConn.RemoteAddr())
rConn.Close()
log.Debug("[HTTP] Closing server Connection.. ", pkt.Domain(), " ", rConn.LocalAddr())
}()
log.Debug("[HTTP] New connection to the server ", pkt.Domain(), " ", rConn.LocalAddr())
go Serve(rConn, lConn, "[HTTP]", lConn.RemoteAddr().String(), pkt.Domain(), pxy.timeout, pxy.bufferSize)
2024-07-22 04:49:18 +00:00
_, err = rConn.Write(pkt.Raw())
if err != nil {
log.Debug("[HTTP] Error sending request to ", pkt.Domain(), err)
return
}
log.Debug("[HTTP] Sent a request to ", pkt.Domain())
Serve(lConn, rConn, "[HTTP]", lConn.RemoteAddr().String(), pkt.Domain(), pxy.timeout, pxy.bufferSize)
2024-07-22 04:49:18 +00:00
}