Skip to content

Commit

Permalink
优化并发逻辑,增加弱口令扫描调试开关
Browse files Browse the repository at this point in the history
  • Loading branch information
selinuxG committed Aug 10, 2023
1 parent 4b0f5b3 commit 0297a98
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 104 deletions.
4 changes: 2 additions & 2 deletions global/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package global

const (
Version = "v3.3.5" //当前版本号
Releasenotes = "优化并发逻辑,增加调试开关,增加识别web指纹" //版本说明
Version = "v3.3.6" //当前版本号
Releasenotes = "优化并发逻辑,增加调试开关" //版本说明
RepoUrl = "https://api.github.com/repos/selinuxg/Golin/releases/latest" //仓库最新版本
)
10 changes: 0 additions & 10 deletions port/crack/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ import (
)

func ftpcon(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
<-ch
}()
select {
case <-ctx.Done():
return
default:
}

c, err := ftp.Dial(fmt.Sprintf("%s:%d", ip, port), ftp.DialWithTimeout(time.Duration(timeout)*time.Second))
if err == nil {
err = c.Login(user, passwd)
Expand Down
9 changes: 0 additions & 9 deletions port/crack/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ import (
)

func mySql(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
<-ch
}()
select {
case <-ctx.Done():
return
default:
}
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local&timeout=%ds", user, passwd, ip, port, "mysql", timeout)
_, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent), // 设置日志级别为 silent
Expand Down
10 changes: 0 additions & 10 deletions port/crack/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ import (
)

func oraclecon(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
<-ch
}()
select {
case <-ctx.Done():
return
default:
}

dataSourceName := fmt.Sprintf("oracle://%s:%s@%s:%d/orcl", user, passwd, ip, port)
db, err := sql.Open("oracle", dataSourceName)
if err == nil {
Expand Down
6 changes: 0 additions & 6 deletions port/crack/pgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import (
)

func pgsql(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer done(ch, wg)
select {
case <-ctx.Done():
return
default:
}
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=postgres port=%d sslmode=disable TimeZone=Asia/Shanghai connect_timeout=%d", ip, user, passwd, port, timeout)
_, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
Expand Down
6 changes: 0 additions & 6 deletions port/crack/rdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ type Client struct {
}

func rdpcon(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer done(ch, wg)
select {
case <-ctx.Done():
return
default:
}
glog.SetLevel(5) //禁止日志输出
logger := log.New(os.Stdout, "", 0)
glog.SetLogger(logger)
Expand Down
10 changes: 0 additions & 10 deletions port/crack/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ import (
var ctx = context.Background()

func rediscon(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
<-ch
}()
select {
case <-ctx.Done():
return
default:
}

client := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", ip, port),
Username: user,
Expand Down
30 changes: 28 additions & 2 deletions port/crack/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"fmt"
"github.com/fatih/color"
"golin/global"
"strconv"
"sync"
"time"
)

// ConnectionFunc 定义一个函数类型
Expand All @@ -29,7 +31,7 @@ var connectionFuncs = map[string]ConnectionFunc{
func Run(host, port string, Timeout, chanCount int, mode string) {
ch := make(chan struct{}, chanCount)
wg := sync.WaitGroup{}
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(Timeout))
defer cancel() //确保所有的goroutine都已经退出
newport, _ := strconv.Atoi(port)

Expand All @@ -41,7 +43,7 @@ func Run(host, port string, Timeout, chanCount int, mode string) {
ch <- struct{}{}
wg.Add(1)
if connFunc, ok := connectionFuncs[mode]; ok {
go connFunc(ctx, cancel, host, user, passwd, newport, Timeout, ch, &wg)
go crackOnce(ctx, cancel, host, user, passwd, newport, Timeout, ch, &wg, connFunc, mode)
} else {
wg.Done()
<-ch
Expand All @@ -53,6 +55,9 @@ func Run(host, port string, Timeout, chanCount int, mode string) {
}

func end(host, user, passwd string, port int, mode string) {
global.PrintLock.Lock()
defer global.PrintLock.Unlock()

fmt.Printf("\033[2K\r") // 擦除整行
fmt.Printf("\r| %-2s | %-15s | %-4d |%-6s|%-4s|%-50s \n",
fmt.Sprintf("%s", color.GreenString("%s", "✓")),
Expand All @@ -64,7 +69,28 @@ func end(host, user, passwd string, port int, mode string) {
)
fmt.Printf("\033[2K\r") // 擦除整行
}

func done(ch <-chan struct{}, wg *sync.WaitGroup) {
<-ch
wg.Done()
}

func crackOnce(ctx context.Context, cancel context.CancelFunc, host, user, passwd string, newport, timeout int, ch <-chan struct{}, wg *sync.WaitGroup, connFunc ConnectionFunc, key string) {
defer done(ch, wg)

hasDone := make(chan struct{}, 1)
go func() {
connFunc(ctx, cancel, host, user, passwd, newport, timeout, ch, wg)
hasDone <- struct{}{}
}()

select {
case <-hasDone:
return
case <-ctx.Done():
if global.Debug {
fmt.Println(key, host, user, passwd, "time out")
}
return
}
}
10 changes: 0 additions & 10 deletions port/crack/smb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ import (
)

func smbcon(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
<-ch
}()
select {
case <-ctx.Done():
return
default:
}

options := smb.Options{
Host: ip,
Port: port,
Expand Down
10 changes: 0 additions & 10 deletions port/crack/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ import (
)

func sqlservercon(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
<-ch
}()
select {
case <-ctx.Done():
return
default:
}

dsn := fmt.Sprintf("sqlserver://%s:%s@%s:%d?database=master&timeout=%ds", user, passwd, ip, port, timeout)
_, err := gorm.Open(sqlserver.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
Expand Down
9 changes: 0 additions & 9 deletions port/crack/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ import (
)

func SSH(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
<-ch
}()
select {
case <-ctx.Done():
return
default:
}
configssh := &ssh.ClientConfig{
Timeout: time.Duration(timeout) * time.Second, // ssh连接timeout时间
User: user,
Expand Down
10 changes: 0 additions & 10 deletions port/crack/telnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ import (
)

func telnetcon(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
<-ch
}()
select {
case <-ctx.Done():
return
default:
}

conn, err := telnet.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), time.Duration(timeout))
if err != nil {
return
Expand Down
10 changes: 0 additions & 10 deletions port/crack/tomcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ import (
)

func tomcat(ctx context.Context, cancel context.CancelFunc, ip, user, passwd string, port, timeout int, ch <-chan struct{}, wg *sync.WaitGroup) {
defer func() {
wg.Done()
<-ch
}()
select {
case <-ctx.Done():
return
default:
}

url := fmt.Sprintf("%s:%d", ip, port)
base64passwd := fmt.Sprintf("%s:%s", user, passwd)
base64passwd = base64.StdEncoding.EncodeToString([]byte(base64passwd))
Expand Down

0 comments on commit 0297a98

Please sign in to comment.