mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 14:26:31 +00:00
update capsulation
This commit is contained in:
parent
c97539cb3f
commit
fefdb5efdd
26
net/conn.go
26
net/conn.go
@ -11,27 +11,27 @@ import (
|
||||
const BUF_SIZE = 1024
|
||||
|
||||
type Conn struct {
|
||||
Conn net.Conn
|
||||
conn net.Conn
|
||||
}
|
||||
|
||||
func (conn *Conn) Close() {
|
||||
conn.Conn.Close()
|
||||
func (c *Conn) Close() {
|
||||
c.conn.Close()
|
||||
}
|
||||
|
||||
func (conn *Conn) RemoteAddr() net.Addr {
|
||||
return conn.Conn.RemoteAddr()
|
||||
func (c *Conn) RemoteAddr() net.Addr {
|
||||
return c.conn.RemoteAddr()
|
||||
}
|
||||
|
||||
func (conn *Conn) LocalAddr() net.Addr {
|
||||
return conn.Conn.LocalAddr()
|
||||
func (c *Conn) LocalAddr() net.Addr {
|
||||
return c.conn.LocalAddr()
|
||||
}
|
||||
|
||||
func (conn *Conn) Read(b []byte) (n int, err error) {
|
||||
return conn.Conn.Read(b)
|
||||
func (c *Conn) Read(b []byte) (n int, err error) {
|
||||
return c.conn.Read(b)
|
||||
}
|
||||
|
||||
func (conn *Conn) Write(b []byte) (n int, err error) {
|
||||
return conn.Conn.Write(b)
|
||||
func (c *Conn) Write(b []byte) (n int, err error) {
|
||||
return c.conn.Write(b)
|
||||
}
|
||||
|
||||
func (conn *Conn) WriteChunks(c [][]byte) (n int, err error) {
|
||||
@ -68,7 +68,7 @@ func (conn *Conn) ReadBytes() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
||||
ip, err := doh.Lookup(p.Domain)
|
||||
ip, err := doh.Lookup(p.Domain())
|
||||
if err != nil {
|
||||
log.Debug("[HTTPS] Error looking up for domain: ", err)
|
||||
}
|
||||
@ -96,7 +96,7 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
||||
}
|
||||
|
||||
func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
|
||||
ip, err := doh.Lookup(p.Domain)
|
||||
ip, err := doh.Lookup(p.Domain())
|
||||
if err != nil {
|
||||
log.Debug("[HTTPS] Error looking up for domain: ", err)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ func Listen(network, address string) (Listener, error) {
|
||||
return Listener{}, err
|
||||
}
|
||||
|
||||
return Listener{Listener: l}, nil
|
||||
return Listener{listener: l}, nil
|
||||
}
|
||||
|
||||
func Dial(network, address string) (Conn, error) {
|
||||
@ -19,5 +19,5 @@ func Dial(network, address string) (Conn, error) {
|
||||
return Conn{}, err
|
||||
}
|
||||
|
||||
return Conn{Conn: conn}, nil
|
||||
return Conn{conn: conn}, nil
|
||||
}
|
||||
|
@ -5,14 +5,14 @@ import (
|
||||
)
|
||||
|
||||
type Listener struct {
|
||||
Listener net.Listener
|
||||
listener net.Listener
|
||||
}
|
||||
|
||||
func (l *Listener) Accept() (Conn, error) {
|
||||
conn, err := l.Listener.Accept()
|
||||
conn, err := l.listener.Accept()
|
||||
if err != nil {
|
||||
return Conn{}, err
|
||||
}
|
||||
|
||||
return Conn{Conn: conn}, nil
|
||||
return Conn{conn: conn}, nil
|
||||
}
|
||||
|
@ -41,32 +41,46 @@ var validMethod = map[string]struct{}{
|
||||
}
|
||||
|
||||
type HttpPacket struct {
|
||||
Raw []byte
|
||||
Method string
|
||||
Domain string
|
||||
Version string
|
||||
raw []byte
|
||||
method string
|
||||
domain string
|
||||
version string
|
||||
}
|
||||
|
||||
func NewHttpPacket(raw []byte) HttpPacket {
|
||||
method, domain, version := parse(raw)
|
||||
|
||||
return HttpPacket{
|
||||
Raw: raw,
|
||||
Method: method,
|
||||
Domain: domain,
|
||||
Version: version,
|
||||
raw: raw,
|
||||
method: method,
|
||||
domain: domain,
|
||||
version: version,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *HttpPacket) IsValidMethod() bool {
|
||||
if _, exists := validMethod[r.Method]; exists {
|
||||
func (p *HttpPacket) Raw() []byte {
|
||||
return p.raw
|
||||
}
|
||||
func (p *HttpPacket) Method() string {
|
||||
return p.method
|
||||
}
|
||||
func (p *HttpPacket) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
func (p *HttpPacket) Version() string {
|
||||
return p.version
|
||||
}
|
||||
|
||||
func (p *HttpPacket) IsValidMethod() bool {
|
||||
if _, exists := validMethod[p.Method()]; exists {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *HttpPacket) IsConnectMethod() bool {
|
||||
return r.Method == "CONNECT"
|
||||
func (p *HttpPacket) IsConnectMethod() bool {
|
||||
return p.Method() == "CONNECT"
|
||||
}
|
||||
|
||||
func parse(raw []byte) (string, string, string) {
|
||||
|
@ -1,19 +1,23 @@
|
||||
package packet
|
||||
|
||||
type HttpsPacket struct {
|
||||
Raw []byte
|
||||
raw []byte
|
||||
}
|
||||
|
||||
func NewHttpsPacket(raw []byte) HttpsPacket {
|
||||
return HttpsPacket{
|
||||
Raw: raw,
|
||||
raw: raw,
|
||||
}
|
||||
}
|
||||
|
||||
func (r HttpsPacket) SplitInChunks() [][]byte {
|
||||
if len(r.Raw) < 1 {
|
||||
return [][]byte{r.Raw}
|
||||
func (p *HttpsPacket) Raw() []byte {
|
||||
return p.raw
|
||||
}
|
||||
|
||||
func (p *HttpsPacket) SplitInChunks() [][]byte {
|
||||
if len(p.Raw()) < 1 {
|
||||
return [][]byte{p.Raw()}
|
||||
}
|
||||
|
||||
return [][]byte{(r.Raw)[:1], (r.Raw)[1:]}
|
||||
return [][]byte{(p.Raw())[:1], (p.Raw())[1:]}
|
||||
}
|
||||
|
@ -9,23 +9,27 @@ import (
|
||||
)
|
||||
|
||||
type Proxy struct {
|
||||
Port string
|
||||
port string
|
||||
}
|
||||
|
||||
func New(port string) *Proxy {
|
||||
return &Proxy{
|
||||
Port: port,
|
||||
port: port,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Proxy) Port() string {
|
||||
return p.port
|
||||
}
|
||||
|
||||
func (p *Proxy) Start() {
|
||||
l, err := net.Listen("tcp", ":"+p.Port)
|
||||
l, err := net.Listen("tcp", ":"+p.Port())
|
||||
if err != nil {
|
||||
log.Fatal("Error creating listener: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
log.Println("Created a listener on :", p.Port)
|
||||
log.Println("Created a listener on :", p.Port())
|
||||
|
||||
for {
|
||||
conn, err := l.Accept()
|
||||
@ -45,20 +49,20 @@ func (p *Proxy) Start() {
|
||||
}
|
||||
log.Debug("Client sent data: ", len(b))
|
||||
|
||||
r := packet.NewHttpPacket(b)
|
||||
log.Debug("New request: \n\n" + string(r.Raw))
|
||||
pkt := packet.NewHttpPacket(b)
|
||||
log.Debug("New request: \n\n" + string(pkt.Raw()))
|
||||
|
||||
if !r.IsValidMethod() {
|
||||
log.Println("Unsupported method: ", r.Method)
|
||||
if !pkt.IsValidMethod() {
|
||||
log.Println("Unsupported method: ", pkt.Method())
|
||||
return
|
||||
}
|
||||
|
||||
if r.IsConnectMethod() {
|
||||
if pkt.IsConnectMethod() {
|
||||
log.Debug("HTTPS Requested")
|
||||
conn.HandleHttps(r)
|
||||
conn.HandleHttps(pkt)
|
||||
} else {
|
||||
log.Debug("HTTP Requested.")
|
||||
conn.HandleHttp(r)
|
||||
conn.HandleHttp(pkt)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user