Skip to content

Commit

Permalink
fixing http dpi bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
uoosef committed Sep 3, 2023
1 parent 49d519c commit 69893b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
23 changes: 15 additions & 8 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@ package server

import (
"bufio"
"bytes"
"errors"
"io"
"net/http"
)

// ParseHTTPHost parses the head of the first HTTP request on conn and returns
// a new, unread connection with metadata for virtual host muxing
func ParseHTTPHost(rd io.Reader) (string, error) {
func ParseHTTPHost(rd io.Reader) (string, []byte, error) {
var request *http.Request
var err error
if request, err = http.ReadRequest(bufio.NewReader(rd)); err != nil {
return "", err
return "", nil, err
}

// You probably don't need access to the request body and this makes the API
// simpler by allowing you to call Free() optionally
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
defer func() {
_ = request.Body.Close()
}()

}
}(request.Body)
if request.Host == "" {
return "", nil, errors.New("host not found")
}
host := request.Host

return request.Host, nil
var buff bytes.Buffer
request.Write(&buff)
b := bytes.Replace(buff.Bytes(), []byte("Host:"), []byte("hOSt:"), -1)
return host, b, nil
}
19 changes: 11 additions & 8 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"bepass/utils"
"bytes"
"context"
"errors"
"fmt"
"io"
"math/rand"
Expand Down Expand Up @@ -57,26 +58,28 @@ type Server struct {
}

// getHostname This function extracts the tls sni or http
func (s *Server) getHostname(data []byte) ([]byte, error) {
func (s *Server) getHostname(data []byte) ([]byte, []byte, error) {
hello, err := ReadClientHello(bytes.NewReader(data))
if err != nil {
host, err := ParseHTTPHost(bytes.NewReader(data))
host, data_, err := ParseHTTPHost(bytes.NewReader(data))
if err != nil {
return nil, err
return nil, data, err
}
return []byte(host), nil
return []byte(host), data_, errors.New("http request packet")
}
return []byte(hello.ServerName), nil
return []byte(hello.ServerName), data, nil
}

func (s *Server) getChunkedPackets(data []byte) map[int][]byte {
chunks := make(map[int][]byte)
hostname, err := s.getHostname(data)
hostname, data_, err := s.getHostname(data)
if hostname != nil {
logger.Infof("Hostname %s", string(hostname))
}
if err != nil {
chunks[0] = data
chunks[0] = data_
return chunks
}
logger.Infof("Hostname %s", string(hostname))
index := bytes.Index(data, hostname)
if index == -1 {
return nil
Expand Down

0 comments on commit 69893b7

Please sign in to comment.