Merge pull request #39 from dqhieuu/main

Add whitelist URL, whitelist regex to disable DPI bypassing on unwanted pages
This commit is contained in:
xvzc 2023-04-25 22:20:19 +09:00 committed by GitHub
commit 49f7138d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 8 deletions

View File

@ -3,17 +3,34 @@ package main
import (
"os"
"os/signal"
"regexp"
"strings"
"syscall"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/xvzc/SpoofDPI/doh"
"github.com/xvzc/SpoofDPI/packet"
"github.com/xvzc/SpoofDPI/proxy"
"github.com/xvzc/SpoofDPI/util"
)
func main() {
addr, port, dns, debug, banner := util.ParseArgs()
addr, port, dns, debug, banner, allowedHosts, allowedPattern := util.ParseArgs()
if(len(*allowedHosts) > 0) {
var escapedUrls []string
for _, host := range *allowedHosts {
escapedUrls = append(escapedUrls, regexp.QuoteMeta(host))
}
allowedHostsRegex := strings.Join(escapedUrls, "|")
packet.UrlsMatcher = regexp.MustCompile(allowedHostsRegex)
}
if(allowedPattern != "") {
packet.PatternMatcher = regexp.MustCompile(allowedPattern)
}
p := proxy.New(addr, port)
doh.Init(dns)

View File

@ -1,5 +1,9 @@
package packet
import (
"regexp"
)
type HttpsPacket struct {
raw []byte
}
@ -14,10 +18,22 @@ func (p *HttpsPacket) Raw() []byte {
return p.raw
}
var PatternMatcher *regexp.Regexp
var UrlsMatcher *regexp.Regexp
func (p *HttpsPacket) SplitInChunks() [][]byte {
if len(p.Raw()) < 1 {
return [][]byte{p.Raw()}
}
// If the packet matches the pattern or the URLs, we don't split it
if PatternMatcher != nil || UrlsMatcher != nil {
if (PatternMatcher != nil && PatternMatcher.Match(p.Raw())) || (UrlsMatcher != nil && UrlsMatcher.Match(p.Raw())) {
return [][]byte{(p.Raw())[:1], (p.Raw())[1:]}
}
return [][]byte{p.Raw()}
}
return [][]byte{(p.Raw())[:1], (p.Raw())[1:]}
}

View File

@ -55,6 +55,12 @@ Usage: spoof-dpi [options...]
--port=<port> | default: 8080
--debug=<bool> | default: false
--banner=<bool> | default: true
--url=<url> | Can be used multiple times. If set,
| it will bypass DPI only for this url.
| Example: --url=google.com --url=github.com
--pattern=<regex> | If set, it will bypass DPI only for packets
| that matches this regex pattern.
| Example: --pattern="google|github"
```
> If you are using any vpn extensions such as Hotspot Shield in Chrome browser,
go to Settings > Extensions, and disable them.

View File

@ -7,16 +7,31 @@ import (
"github.com/pterm/pterm"
)
func ParseArgs() (string, int, string, bool, bool) {
type ArrayFlags []string
func (i *ArrayFlags) String() string {
return "my string representation"
}
func (i *ArrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
func ParseArgs() (string, int, string, bool, bool, *ArrayFlags, string) {
addr := flag.String("addr", "127.0.0.1", "Listen addr")
port := flag.Int("port", 8080, "port")
dns := flag.String("dns", "8.8.8.8", "DNS server")
debug := flag.Bool("debug", false, "true | false")
banner := flag.Bool("banner", true, "true | false")
var allowedUrls ArrayFlags
flag.Var(&allowedUrls, "url", "Bypass DPI only on this url, can be passed multiple times")
allowedPattern := flag.String("pattern", "", "Bypass DPI only on packets matching this regex pattern")
flag.Parse()
return *addr, *port, *dns, *debug, *banner
return *addr, *port, *dns, *debug, *banner, &allowedUrls, *allowedPattern
}
func PrintColoredBanner(addr string, port int, dns string, debug bool) {