Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot/go_modules/dev/golang.org/x/crypto…
Browse files Browse the repository at this point in the history
…-0.31.0
  • Loading branch information
x90skysn3k authored Dec 30, 2024
2 parents d2e4e2a + b0386a7 commit 771ace3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Brutespray

![Version](https://img.shields.io/badge/Version-2.3.0-red)[![goreleaser](https://github.com/x90skysn3k/brutespray/actions/workflows/release.yml/badge.svg)](https://github.com/x90skysn3k/brutespray/actions/workflows/release.yml)[![Go Report Card](https://goreportcard.com/badge/github.com/x90skysn3k/brutespray)](https://goreportcard.com/report/github.com/x90skysn3k/brutespray)
![Version](https://img.shields.io/badge/Version-2.3.1-red)[![goreleaser](https://github.com/x90skysn3k/brutespray/actions/workflows/release.yml/badge.svg)](https://github.com/x90skysn3k/brutespray/actions/workflows/release.yml)[![Go Report Card](https://goreportcard.com/badge/github.com/x90skysn3k/brutespray)](https://goreportcard.com/report/github.com/x90skysn3k/brutespray)

Created by: Shane Young/@t1d3nio && Jacob Robles/@shellfail

Expand Down
3 changes: 1 addition & 2 deletions brute/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func BruteSSH(host string, port int, user, password string, timeout time.Duratio

var err error
var conn net.Conn
var service = "ssh"

cm, err := modules.NewConnectionManager(socks5, timeout, netInterface)
if err != nil {
Expand All @@ -37,7 +36,7 @@ func BruteSSH(host string, port int, user, password string, timeout time.Duratio

conn, err = cm.Dial("tcp", fmt.Sprintf("%s:%d", host, port))
if err != nil {
modules.PrintSocksError(service, fmt.Sprintf("%v", err))
//modules.PrintSocksError(service, fmt.Sprintf("%v", err))
return false, false
}

Expand Down
2 changes: 1 addition & 1 deletion brutespray/brutespray.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var masterServiceList = []string{"ssh", "ftp", "smtp", "mssql", "telnet", "smbnt

var BetaServiceList = []string{"asterisk", "nntp", "oracle", "xmpp", "rdp"}

var version = "v2.3.0"
var version = "v2.3.1"

func Execute() {
user := flag.String("u", "", "Username or user list to bruteforce")
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ require (
github.com/x90skysn3k/grdp v0.0.0-20240614212340-82874dbd1eae
go.mongodb.org/mongo-driver v1.17.1
golang.org/x/crypto v0.31.0
golang.org/x/net v0.32.0
golang.org/x/net v0.33.0

gosrc.io/xmpp v0.5.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
79 changes: 64 additions & 15 deletions modules/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package modules
import (
"fmt"
"net"
"sync"
"time"

"golang.org/x/net/proxy"
)

type ConnectionManager struct {
Socks5 string
Timeout time.Duration
Iface string
Dialer proxy.Dialer
DialFunc func(network, address string) (net.Conn, error)
Socks5 string
Timeout time.Duration
Iface string
Dialer proxy.Dialer
DialFunc func(network, address string) (net.Conn, error)
ConnPool map[string]chan net.Conn
PoolMutex sync.Mutex
}

func NewConnectionManager(socks5 string, timeout time.Duration, iface ...string) (*ConnectionManager, error) {
Expand All @@ -30,26 +33,34 @@ func NewConnectionManager(socks5 string, timeout time.Duration, iface ...string)
}

cm := &ConnectionManager{
Socks5: socks5,
Timeout: timeout,
Iface: ifaceName,
Socks5: socks5,
Timeout: timeout,
Iface: ifaceName,
ConnPool: make(map[string]chan net.Conn),
}

ipAddr, err := GetIPv4Address(ifaceName)
if err != nil {
return nil, err
}
localAddr := &net.TCPAddr{IP: ipAddr}

if socks5 != "" {
dialer, err := proxy.SOCKS5("tcp", socks5, nil, nil)
if err != nil {
PrintSocksError("connection_manager", fmt.Sprintf("%v", err))
return nil, err
}
cm.Dialer = dialer
cm.DialFunc = cm.Dialer.Dial
cm.DialFunc = func(network, address string) (net.Conn, error) {
conn, err := dialer.Dial(network, address)
if err != nil {
PrintSocksError("Failed to connect to proxy:", fmt.Sprintf("%v", err))
}
return conn, err
}
} else {
// Bind to specific network interface
ipAddr, err := GetIPv4Address(ifaceName)
if err != nil {
return nil, err
}
localAddr := &net.TCPAddr{IP: ipAddr}
dialer := &net.Dialer{Timeout: timeout, LocalAddr: localAddr}
cm.DialFunc = dialer.Dial
//fmt.Printf("Binding to local address: %s\n", localAddr)
Expand All @@ -59,7 +70,45 @@ func NewConnectionManager(socks5 string, timeout time.Duration, iface ...string)
}

func (cm *ConnectionManager) Dial(network, address string) (net.Conn, error) {
return cm.DialFunc(network, address)
key := fmt.Sprintf("%s:%s", network, address)

cm.PoolMutex.Lock()
if _, ok := cm.ConnPool[key]; !ok {
cm.ConnPool[key] = make(chan net.Conn, 10)
}
cm.PoolMutex.Unlock()

select {
case conn := <-cm.ConnPool[key]:
return conn, nil
default:
conn, err := cm.DialFunc(network, address)
if err != nil {
return nil, err
}
return conn, nil
}
}

func (cm *ConnectionManager) Release(conn net.Conn) {
if conn == nil {
return
}

cm.PoolMutex.Lock()
defer cm.PoolMutex.Unlock()

key := fmt.Sprintf("%s:%s", conn.RemoteAddr().Network(), conn.RemoteAddr().String())

if _, ok := cm.ConnPool[key]; !ok {
cm.ConnPool[key] = make(chan net.Conn, 10)
}

select {
case cm.ConnPool[key] <- conn:
default:
conn.Close()
}
}

func (cm *ConnectionManager) DialUDP(network, address string) (*net.UDPConn, error) {
Expand Down

0 comments on commit 771ace3

Please sign in to comment.