Skip to content

Commit

Permalink
update 1.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
qiwentaidi committed Nov 29, 2024
1 parent 657442a commit 2e6b306
Show file tree
Hide file tree
Showing 113 changed files with 2,863 additions and 3,058 deletions.
90 changes: 90 additions & 0 deletions core/exp/nacos/extract.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package nacos

import (
"bufio"
"fmt"
"os"
"path/filepath"
"slack-wails/lib/structs"
"strings"
)

// 定义关键词分类
var categories = map[string][]string{
"Auth": {"username", "password"},
"OSS": {"accesskey", "secret"},
"Database": {"jdbc", "redis", "elasticsearch", "database", "mongo", "mssql", "mysql", "oracle", "postgres", "sqlserver"},
}

// 统计单个文件中每个类别关键词的出现次数
func countKeywordsInFile(filePath string) (structs.NacosNode, error) {
file, err := os.Open(filePath)
if err != nil {
return structs.NacosNode{}, err
}
defer file.Close()

// 初始化统计信息
nodeInfo := structs.NacosNode{}

// 逐行读取文件
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := strings.ToLower(scanner.Text()) // 转换为小写
for category, keywords := range categories {
for _, keyword := range keywords {
if strings.Contains(line, keyword) {
switch category {
case "Auth":
nodeInfo.Auth++
case "OSS":
nodeInfo.OSS++
case "Database":
nodeInfo.Database++
}
}
}
}
}

if err := scanner.Err(); err != nil {
return structs.NacosNode{}, err
}
return nodeInfo, nil
}

// 遍历目录并统计每个文件的关键词出现次数,返回结果数组
func ProcessDirectory(dir string) []structs.NacosConfig {
var results []structs.NacosConfig

err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

// 只处理 .yaml 或 .yml 文件
if !info.IsDir() {
nodeInfo, err := countKeywordsInFile(path)
if err != nil {
fmt.Printf("Error processing file %s: %v\n", path, err)
return nil
}

// 检查是否有关键词匹配
if nodeInfo.Auth > 0 || nodeInfo.OSS > 0 || nodeInfo.Database > 0 {
// 添加结果到数组中
results = append(results, structs.NacosConfig{
Name: path,
NodeInfo: nodeInfo,
})
}
}
return nil
})

if err != nil {
fmt.Printf("Error walking directory: %v\n", err)
}

return results
}
23 changes: 23 additions & 0 deletions core/exp/nacos/extract_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package nacos

import (
"fmt"
"testing"
)

func TestExtract(t *testing.T) {
// 设置目标目录
dir := "./configs" // 替换为实际的配置文件目录路径

// 获取所有文件的统计结果
results := ProcessDirectory(dir)

// 输出总结果
fmt.Println("Final Results:")
for _, result := range results {
fmt.Printf("File: %s\n", result.Name)
fmt.Printf(" Auth (账号密码): %d\n", result.NodeInfo.Auth)
fmt.Printf(" OSS: %d\n", result.NodeInfo.OSS)
fmt.Printf(" Database: %d\n", result.NodeInfo.Database)
}
}
106 changes: 106 additions & 0 deletions core/portscan/adb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package portscan

import (
"context"
"fmt"
"slack-wails/lib/gologger"
"strings"
"time"

"github.com/wailsapp/wails/v2/pkg/runtime"
)

func AdbScan(ctx context.Context, address string) {
result := "ADB> host::features=shell_v2,cmd,stat_v2,ls_v2,fixed_push_mkdir,apex,abb,fixed_push_symlink_timestamp,abb_exec,remount_shell,track_app,sendrecv_v2,sendrecv_v2_brotli,sendrecv_v2_lz4,sendrecv_v2_zstd,sendrecv_v2_dry_run_send,openscreen_mdns\n"
conn, err := WrapperTcpWithTimeout("tcp", address, time.Duration(6)*time.Second)
if err == nil {
defer func() {
if conn != nil {
_ = conn.Close()
}
}()
} else {
gologger.Info(ctx, fmt.Sprintf("connect %s failed", address))
return
}

_, err = conn.Write([]byte{0x43, 0x4e, 0x58, 0x4e, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x10, 0x00, 0xea, 0x00, 0x00, 0x00,
0x44, 0x5b, 0x00, 0x00, 0xbc, 0xb1, 0xa7, 0xb1,
0x68, 0x6f, 0x73, 0x74, 0x3a, 0x3a, 0x66, 0x65,
0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x3d, 0x73,
0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x76, 0x32, 0x2c,
0x63, 0x6d, 0x64, 0x2c, 0x73, 0x74, 0x61, 0x74,
0x5f, 0x76, 0x32, 0x2c, 0x6c, 0x73, 0x5f, 0x76,
0x32, 0x2c, 0x66, 0x69, 0x78, 0x65, 0x64, 0x5f,
0x70, 0x75, 0x73, 0x68, 0x5f, 0x6d, 0x6b, 0x64,
0x69, 0x72, 0x2c, 0x61, 0x70, 0x65, 0x78, 0x2c,
0x61, 0x62, 0x62, 0x2c, 0x66, 0x69, 0x78, 0x65,
0x64, 0x5f, 0x70, 0x75, 0x73, 0x68, 0x5f, 0x73,
0x79, 0x6d, 0x6c, 0x69, 0x6e, 0x6b, 0x5f, 0x74,
0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70,
0x2c, 0x61, 0x62, 0x62, 0x5f, 0x65, 0x78, 0x65,
0x63, 0x2c, 0x72, 0x65, 0x6d, 0x6f, 0x75, 0x6e,
0x74, 0x5f, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x2c,
0x74, 0x72, 0x61, 0x63, 0x6b, 0x5f, 0x61, 0x70,
0x70, 0x2c, 0x73, 0x65, 0x6e, 0x64, 0x72, 0x65,
0x63, 0x76, 0x5f, 0x76, 0x32, 0x2c, 0x73, 0x65,
0x6e, 0x64, 0x72, 0x65, 0x63, 0x76, 0x5f, 0x76,
0x32, 0x5f, 0x62, 0x72, 0x6f, 0x74, 0x6c, 0x69,
0x2c, 0x73, 0x65, 0x6e, 0x64, 0x72, 0x65, 0x63,
0x76, 0x5f, 0x76, 0x32, 0x5f, 0x6c, 0x7a, 0x34,
0x2c, 0x73, 0x65, 0x6e, 0x64, 0x72, 0x65, 0x63,
0x76, 0x5f, 0x76, 0x32, 0x5f, 0x7a, 0x73, 0x74,
0x64, 0x2c, 0x73, 0x65, 0x6e, 0x64, 0x72, 0x65,
0x63, 0x76, 0x5f, 0x76, 0x32, 0x5f, 0x64, 0x72,
0x79, 0x5f, 0x72, 0x75, 0x6e, 0x5f, 0x73, 0x65,
0x6e, 0x64, 0x2c, 0x6f, 0x70, 0x65, 0x6e, 0x73,
0x63, 0x72, 0x65, 0x65, 0x6e, 0x5f, 0x6d, 0x64,
0x6e, 0x73})
if err != nil {
gologger.Info(ctx, fmt.Sprintf("write %s failed", address))
return
}

err = conn.SetReadDeadline(time.Now().Add(time.Duration(6) * time.Second))
if err != nil {
gologger.Info(ctx, fmt.Sprintf("set read deadline for %s failed", address))
return
}

buf := make([]byte, 0x1000)
n, err := conn.Read(buf)
if err != nil {
gologger.Info(ctx, fmt.Sprintf("read from %s failed", address))
return
}

if n > 4 && string(buf[:4]) != "CNXN" {
gologger.Info(ctx, "ADB需要授权/非ADB服务")
return
}

if strings.Contains(string(buf[:n]), "ro.product.name") {
result += string(buf[24:n]) + "\n"
} else {
buf = make([]byte, 0x1000)
n, err = conn.Read(buf)
if err != nil {
gologger.Info(ctx, fmt.Sprintf("read from %s failed", address))
return
}

result += string(buf[:n]) + "\n"
}

if result != "" {
runtime.EventsEmit(ctx, "bruteResult", Burte{
Status: true,
Host: address,
Protocol: "adb",
Username: "unauthorized",
Password: "",
})
return
}
}
53 changes: 53 additions & 0 deletions core/portscan/jdwp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package portscan

import (
"context"
"fmt"
"slack-wails/lib/gologger"
"strings"
"time"

"github.com/wailsapp/wails/v2/pkg/runtime"
)

func JdwpScan(ctx context.Context, address string) {
client, err := WrapperTcpWithTimeout("tcp", address, time.Duration(6)*time.Second)
defer func() {
if client != nil {
client.Close()
}
}()
if err != nil {
gologger.Info(ctx, fmt.Sprintf("connect %s failed", address))
return
}
err = client.SetDeadline(time.Now().Add(time.Duration(6) * time.Second))
if err != nil {
gologger.Info(ctx, fmt.Sprintf("connect %s failed", address))
return
}
_, err = client.Write([]byte("JDWP-Handshake"))
if err != nil {
gologger.Info(ctx, fmt.Sprintf("write jdwp-handshake to %s failed", address))
return
}

rev := make([]byte, 1024)
n, errRead := client.Read(rev)
if errRead != nil {
gologger.Info(ctx, fmt.Sprintf("read %s err: %s", address, errRead))
return
}
if !strings.Contains(string(rev[:n]), "JDWP-Handshake") {
// 不是JDWP
gologger.Info(ctx, fmt.Sprintf("%s is not jdwp", address))
return
}
runtime.EventsEmit(ctx, "bruteResult", Burte{
Status: true,
Host: address,
Protocol: "jdwp",
Username: "unauthorized",
Password: "",
})
}
19 changes: 14 additions & 5 deletions core/portscan/portbrute.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,34 @@ type Burte struct {

var ExitBruteFunc = false

var DefaultPorts = map[string]string{
var defaultPorts = map[string]string{
"ftp": "21",
"ssh": "22",
"telnet": "23",
"ldap": "389",
"smb": "445", // SMB 通常使用445端口
"socks5": "1080",
"rmi": "1099",
"oracle": "1521",
"mssql": "1433",
"mqtt": "1883",
"mysql": "3306",
"rdp": "3389",
"postgresql": "5432",
"adb": "5555",
"vnc": "5900",
"redis": "6379",
"jdwp": "8000",
"memcached": "11211",
"mongodb": "27017",
}

// AddDefaultPort 检查并为给定的主机添加默认端口号
func AddDefaultPort(scheme, host string) string {
// 检查并为给定的主机添加默认端口号
func addDefaultPort(scheme, host string) string {
if strings.Contains(host, ":") {
return host
}
defaultPort := DefaultPorts[scheme]
defaultPort := defaultPorts[scheme]
return host + ":" + defaultPort
}

Expand All @@ -49,7 +52,7 @@ func PortBrute(ctx context.Context, host string, usernames, passwords []string)
if err != nil {
return
}
u.Host = AddDefaultPort(u.Scheme, u.Host)
u.Host = addDefaultPort(u.Scheme, u.Host)
switch u.Scheme {
case "ftp":
FtpScan(ctx, u.Host, usernames, passwords)
Expand Down Expand Up @@ -83,5 +86,11 @@ func PortBrute(ctx context.Context, host string, usernames, passwords []string)
MqttScan(ctx, u.Host, usernames, passwords)
case "socks5":
Socks5Scan(ctx, u.Host, usernames, passwords)
case "jdwp":
JdwpScan(ctx, u.Host)
case "adb":
AdbScan(ctx, u.Host)
case "rmi":
RmiScan(ctx, u.Host)
}
}
8 changes: 4 additions & 4 deletions core/portscan/portscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type PortResult struct {
HttpTitle string
}

func TcpScan(ctx context.Context, addresses <-chan Address, workers, timeout int) {
func TcpScan(ctx context.Context, addresses <-chan Address, workers, timeout int, proxy *clients.Proxy) {
var id int32
single := make(chan struct{})
retChan := make(chan PortResult)
Expand All @@ -43,7 +43,7 @@ func TcpScan(ctx context.Context, addresses <-chan Address, workers, timeout int
if ExitFunc {
return
}
pr := Connect(add.IP, add.Port, timeout)
pr := Connect(add.IP, add.Port, timeout, proxy)
atomic.AddInt32(&id, 1)
runtime.EventsEmit(ctx, "progressID", id)
if pr.Status {
Expand Down Expand Up @@ -76,10 +76,10 @@ type Address struct {
Port int
}

func Connect(ip string, port, timeout int) PortResult {
func Connect(ip string, port, timeout int, proxy *clients.Proxy) PortResult {
var pr PortResult
scanner := gonmap.New()
status, response := scanner.Scan(ip, port, time.Second*time.Duration(timeout))
status, response := scanner.Scan(ip, port, time.Second*time.Duration(timeout), proxy)
switch status {
case gonmap.Closed:
pr.Status = false
Expand Down
Loading

0 comments on commit 2e6b306

Please sign in to comment.