Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic blacklist functionality #58

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading