SpoofDPI/proxy/http.go

46 lines
1.1 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-08-18 07:33:02 +00:00
log.Debugf("[HTTP] error while parsing port for %s aborting..", pkt.Domain())
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
}
2024-08-18 07:33:02 +00:00
log.Debugf("[HTTP] new connection to the server %s -> %s", rConn.LocalAddr(), pkt.Domain())
2024-07-22 04:49:18 +00:00
2024-08-15 07:50:03 +00:00
go Serve(rConn, lConn, "[HTTP]", pkt.Domain(), lConn.RemoteAddr().String(), pxy.timeout)
2024-07-22 04:49:18 +00:00
_, err = rConn.Write(pkt.Raw())
if err != nil {
2024-08-18 07:33:02 +00:00
log.Debugf("[HTTP] error sending request to %s: %s", pkt.Domain(), err)
2024-07-22 04:49:18 +00:00
return
}
2024-08-18 07:33:02 +00:00
log.Debugf("[HTTP] sent a request to %s", pkt.Domain())
2024-07-22 04:49:18 +00:00
2024-08-15 07:50:03 +00:00
go Serve(lConn, rConn, "[HTTP]", lConn.RemoteAddr().String(), pkt.Domain(), pxy.timeout)
2024-07-22 04:49:18 +00:00
}