mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
Add whitelist URL, whitelist regex to bypass DPI
This commit is contained in:
parent
78de8c398d
commit
d34d95a872
@ -3,17 +3,34 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/xvzc/SpoofDPI/doh"
|
"github.com/xvzc/SpoofDPI/doh"
|
||||||
|
"github.com/xvzc/SpoofDPI/packet"
|
||||||
"github.com/xvzc/SpoofDPI/proxy"
|
"github.com/xvzc/SpoofDPI/proxy"
|
||||||
"github.com/xvzc/SpoofDPI/util"
|
"github.com/xvzc/SpoofDPI/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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)
|
p := proxy.New(addr, port)
|
||||||
doh.Init(dns)
|
doh.Init(dns)
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package packet
|
package packet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
type HttpsPacket struct {
|
type HttpsPacket struct {
|
||||||
raw []byte
|
raw []byte
|
||||||
}
|
}
|
||||||
@ -14,10 +18,22 @@ func (p *HttpsPacket) Raw() []byte {
|
|||||||
return p.raw
|
return p.raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var PatternMatcher *regexp.Regexp
|
||||||
|
var UrlsMatcher *regexp.Regexp
|
||||||
|
|
||||||
func (p *HttpsPacket) SplitInChunks() [][]byte {
|
func (p *HttpsPacket) SplitInChunks() [][]byte {
|
||||||
if len(p.Raw()) < 1 {
|
if len(p.Raw()) < 1 {
|
||||||
return [][]byte{p.Raw()}
|
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:]}
|
return [][]byte{(p.Raw())[:1], (p.Raw())[1:]}
|
||||||
}
|
}
|
||||||
|
16
readme.md
16
readme.md
@ -50,11 +50,17 @@ You can also build your own
|
|||||||
# Usage
|
# Usage
|
||||||
```
|
```
|
||||||
Usage: spoof-dpi [options...]
|
Usage: spoof-dpi [options...]
|
||||||
--addr=<addr> | default: 127.0.0.1
|
--addr=<addr> | default: 127.0.0.1
|
||||||
--dns=<addr> | default: 8.8.8.8
|
--dns=<addr> | default: 8.8.8.8
|
||||||
--port=<port> | default: 8080
|
--port=<port> | default: 8080
|
||||||
--debug=<bool> | default: false
|
--debug=<bool> | default: false
|
||||||
--banner=<bool> | default: true
|
--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,
|
> If you are using any vpn extensions such as Hotspot Shield in Chrome browser,
|
||||||
go to Settings > Extensions, and disable them.
|
go to Settings > Extensions, and disable them.
|
||||||
|
19
util/util.go
19
util/util.go
@ -7,16 +7,31 @@ import (
|
|||||||
"github.com/pterm/pterm"
|
"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")
|
addr := flag.String("addr", "127.0.0.1", "Listen addr")
|
||||||
port := flag.Int("port", 8080, "port")
|
port := flag.Int("port", 8080, "port")
|
||||||
dns := flag.String("dns", "8.8.8.8", "DNS server")
|
dns := flag.String("dns", "8.8.8.8", "DNS server")
|
||||||
debug := flag.Bool("debug", false, "true | false")
|
debug := flag.Bool("debug", false, "true | false")
|
||||||
banner := flag.Bool("banner", true, "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()
|
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) {
|
func PrintColoredBanner(addr string, port int, dns string, debug bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user