Skip to content

Commit

Permalink
Add basic blacklist functionality (#58)
Browse files Browse the repository at this point in the history
* Add basic blacklist functionality

* Cleanup code to match Project style
  • Loading branch information
xXxsomebodyoncetoldmexXx authored Jul 1, 2024
1 parent dee94e0 commit a953e42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions ctrl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Suo5Config struct {
DisableGzip bool `json:"disable_gzip"`
EnableCookiejar bool `json:"enable_cookiejar"`
TestExit string `json:"-"`
ExcludeDomain []string `json:"exclude_domain"`

Offset int `json:"-"`
Header http.Header `json:"-"`
Expand Down
8 changes: 7 additions & 1 deletion ctrl/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net"
"net/http"
"slices"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -52,6 +53,12 @@ func (m *socks5Handler) Handle(conn net.Conn) error {
return err
}

if slices.Contains(m.config.ExcludeDomain, req.Addr.Host) {
defer conn.Close()
log.Infof("drop connection to %s", req.Addr.Host)
return nil
}

log.Infof("start connection to %s", req.Addr.String())
switch req.Cmd {
case gosocks5.CmdConnect:
Expand Down Expand Up @@ -258,7 +265,6 @@ func marshal(m map[string][]byte) []byte {
buf.Write(v)
}
return buf.Bytes()

}

func unmarshal(bs []byte) (map[string][]byte, error) {
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func main() {
Usage: "test a real connection, if success exit(0), else exit(1)",
Hidden: true,
},
&cli.StringSliceFlag{
Name: "exclude_domain",
Aliases: []string{"E"},
Usage: "Exclude certain domain name for proxy, ex -E 'portswigger.net'",
},
}
app.Before = func(c *cli.Context) error {
if c.Bool("debug") {
Expand Down Expand Up @@ -152,6 +157,7 @@ func Action(c *cli.Context) error {
noGzip := c.Bool("no-gzip")
useJar := c.Bool("jar")
testExit := c.String("test-exit")
exclude := c.StringSlice("exclude_domain")

var username, password string
if auth == "" {
Expand Down Expand Up @@ -195,6 +201,7 @@ func Action(c *cli.Context) error {
DisableGzip: noGzip,
EnableCookiejar: useJar,
TestExit: testExit,
ExcludeDomain: exclude,
}
ctx, cancel := signalCtx()
defer cancel()
Expand Down

0 comments on commit a953e42

Please sign in to comment.