Skip to content

Commit a942bac

Browse files
committed
add config panel
1 parent 2de8822 commit a942bac

File tree

4 files changed

+152
-24
lines changed

4 files changed

+152
-24
lines changed

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ require (
2424
github.com/VividCortex/ewma v1.2.0 // indirect
2525
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
2626
github.com/andybalholm/brotli v1.1.0 // indirect
27+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
2728
github.com/chainreactors/words v0.0.0-20240910083848-19a289e8984b // indirect
29+
github.com/charmbracelet/lipgloss v0.13.0 // indirect
30+
github.com/charmbracelet/x/ansi v0.1.4 // indirect
2831
github.com/facebookincubator/nvdtools v0.1.5 // indirect
2932
github.com/fatih/color v1.17.0 // indirect
3033
github.com/go-dedup/megophone v0.0.0-20170830025436-f01be21026f5 // indirect
@@ -37,10 +40,12 @@ require (
3740
github.com/gookit/goutil v0.6.15 // indirect
3841
github.com/klauspost/compress v1.17.8 // indirect
3942
github.com/kr/pretty v0.3.1 // indirect
43+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
4044
github.com/mattn/go-colorable v0.1.13 // indirect
4145
github.com/mattn/go-isatty v0.0.20 // indirect
4246
github.com/mattn/go-runewidth v0.0.15 // indirect
4347
github.com/mitchellh/mapstructure v1.5.0 // indirect
48+
github.com/muesli/termenv v0.15.2 // indirect
4449
github.com/pkg/errors v0.9.1 // indirect
4550
github.com/rivo/uniseg v0.4.7 // indirect
4651
github.com/rogpeppe/go-internal v1.12.0 // indirect

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV
7070
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
7171
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
7272
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
73+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
74+
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
7375
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
7476
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
7577
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
@@ -113,6 +115,10 @@ github.com/chainreactors/words v0.4.1-0.20240510105042-5ba5c2edc508 h1:iT4HWkoZz
113115
github.com/chainreactors/words v0.4.1-0.20240510105042-5ba5c2edc508/go.mod h1:DUDx7PdsMEm5PvVhzkFyppzpiUhQb8dOJaWjVc1SMVk=
114116
github.com/chainreactors/words v0.4.1-0.20240910075300-24fe4facd5a6 h1:QpUlRyzw5wn9avRbTHBKRhV06X79Yj/ghGKn2Gyb9v4=
115117
github.com/chainreactors/words v0.4.1-0.20240910075300-24fe4facd5a6/go.mod h1:zfz367PUmyaX6oAqV9SktVqyRXKlEh0sel9Wsq9dd2c=
118+
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
119+
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
120+
github.com/charmbracelet/x/ansi v0.1.4 h1:IEU3D6+dWwPSgZ6HBH+v6oUuZ/nVawMiWj5831KfiLM=
121+
github.com/charmbracelet/x/ansi v0.1.4/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
116122
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
117123
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
118124
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -332,6 +338,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
332338
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
333339
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
334340
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
341+
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
342+
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
335343
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
336344
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
337345
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
@@ -369,6 +377,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
369377
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
370378
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
371379
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
380+
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
381+
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
372382
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
373383
github.com/panjf2000/ants/v2 v2.9.1 h1:Q5vh5xohbsZXGcD6hhszzGqB7jSSc2/CRr3QKIga8Kw=
374384
github.com/panjf2000/ants/v2 v2.9.1/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=

internal/option.go

Lines changed: 131 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/chainreactors/utils/iutils"
1515
"github.com/chainreactors/words/mask"
1616
"github.com/chainreactors/words/rule"
17+
"github.com/charmbracelet/lipgloss"
1718
"github.com/expr-lang/expr"
1819
"github.com/vbauerster/mpb/v8"
1920
"io/ioutil"
@@ -304,10 +305,6 @@ func (opt *Option) NewRunner() (*Runner, error) {
304305
r.ClientType = ihttp.STANDARD
305306
}
306307

307-
if opt.Threads == DefaultThreads && len(opt.Dictionaries) == 0 {
308-
r.Threads = 1000
309-
}
310-
311308
err = opt.BuildPlugin(r)
312309
if err != nil {
313310
return nil, err
@@ -318,6 +315,10 @@ func (opt *Option) NewRunner() (*Runner, error) {
318315
return nil, err
319316
}
320317

318+
if opt.Threads == DefaultThreads && r.bruteMod {
319+
r.Threads = 1000
320+
}
321+
321322
pkg.DefaultStatistor = pkg.Statistor{
322323
Word: opt.Word,
323324
WordCount: len(r.Wordlist),
@@ -392,6 +393,8 @@ func (opt *Option) NewRunner() (*Runner, error) {
392393
r.Probes = strings.Split(opt.OutputProbe, ",")
393394
}
394395

396+
fmt.Println(opt.PrintConfig(r))
397+
395398
// init output file
396399
if opt.OutputFile != "" {
397400
r.OutputFile, err = files.NewFile(opt.OutputFile, false, false, true)
@@ -435,30 +438,136 @@ func (opt *Option) NewRunner() (*Runner, error) {
435438
return r, nil
436439
}
437440

438-
func (opt *Option) PrintPlugin() {
439-
var s strings.Builder
440-
if opt.CrawlPlugin {
441-
s.WriteString("crawl enable; ")
442-
}
443-
if opt.Finger {
444-
s.WriteString("active fingerprint enable; ")
445-
}
446-
if opt.BakPlugin {
447-
s.WriteString("bak file enable; ")
441+
func (opt *Option) PrintConfig(r *Runner) string {
442+
// 定义颜色样式
443+
keyStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#FFFFFF")).Width(20) // Key 加粗并设定宽度
444+
stringValueStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#FFA07A")) // 字符串样式
445+
arrayValueStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#98FB98")) // 数组样式
446+
numberValueStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#ADD8E6")) // 数字样式
447+
panelWidth := 60 // 调整 panelWidth 使内容稍微靠左
448+
padding := 2 // 减少 padding 以调整布局靠左
449+
450+
// 分割线样式和终端宽度计算
451+
divider := strings.Repeat("─", panelWidth) // 使用"─"符号生成更加连贯的分割线
452+
453+
// 处理不同类型的值
454+
formatValue := func(value interface{}) string {
455+
switch v := value.(type) {
456+
case string:
457+
return stringValueStyle.Render(v)
458+
case []string:
459+
return arrayValueStyle.Render(fmt.Sprintf("%v", v))
460+
case int, int64, float64:
461+
return numberValueStyle.Render(fmt.Sprintf("%v", v))
462+
default:
463+
return stringValueStyle.Render(fmt.Sprintf("%v", v)) // 默认为字符串样式
464+
}
448465
}
449-
if opt.CommonPlugin {
450-
s.WriteString("common file enable; ")
466+
467+
// 处理互斥参数,选择输出有值的那一个
468+
inputSource := ""
469+
if opt.ResumeFrom != "" {
470+
inputSource = lipgloss.JoinHorizontal(lipgloss.Left, "🌀 ", keyStyle.Render("ResumeFrom: "), formatValue(opt.ResumeFrom))
471+
} else if len(opt.URL) > 0 {
472+
inputSource = lipgloss.JoinHorizontal(lipgloss.Left, "🌐 ", keyStyle.Render("URL: "), formatValue(opt.URL))
473+
} else if opt.URLFile != "" {
474+
inputSource = lipgloss.JoinHorizontal(lipgloss.Left, "📂 ", keyStyle.Render("URLFile: "), formatValue(opt.URLFile))
475+
} else if len(opt.CIDRs) > 0 {
476+
inputSource = lipgloss.JoinHorizontal(lipgloss.Left, "📡 ", keyStyle.Render("CIDRs: "), formatValue(opt.CIDRs))
477+
} else if opt.RawFile != "" {
478+
inputSource = lipgloss.JoinHorizontal(lipgloss.Left, "📄 ", keyStyle.Render("RawFile: "), formatValue(opt.RawFile))
479+
}
480+
481+
// Input Options
482+
inputOptions := lipgloss.JoinVertical(lipgloss.Left,
483+
inputSource, // 互斥量处理
484+
485+
// PortRange 展示
486+
lipgloss.JoinHorizontal(lipgloss.Left, "🔢 ", keyStyle.Render("PortRange: "), formatValue(opt.PortRange)),
487+
488+
// Dictionaries 展示
489+
lipgloss.JoinHorizontal(lipgloss.Left, "📚 ", keyStyle.Render("Dictionaries: "), formatValue(opt.Dictionaries)),
490+
491+
// Word, Rules, FilterRule 展开为单独的行
492+
lipgloss.JoinVertical(lipgloss.Left,
493+
lipgloss.JoinHorizontal(lipgloss.Left, "💡 ", keyStyle.Render("Word: "), formatValue(r.Word)),
494+
lipgloss.JoinHorizontal(lipgloss.Left, "📜 ", keyStyle.Render("Rules: "), formatValue(opt.Rules)),
495+
lipgloss.JoinHorizontal(lipgloss.Left, "🔍 ", keyStyle.Render("FilterRule: "), formatValue(opt.FilterRule)),
496+
),
497+
498+
// AppendRule 和 AppendWords 展开为单独的行
499+
lipgloss.JoinVertical(lipgloss.Left,
500+
lipgloss.JoinHorizontal(lipgloss.Left, "🔧 ", keyStyle.Render("AppendRule: "), formatValue(r.AppendRule)),
501+
lipgloss.JoinHorizontal(lipgloss.Left, "🧩 ", keyStyle.Render("AppendWords: "), formatValue(len(r.AppendWords))),
502+
),
503+
)
504+
505+
// Output Options
506+
outputOptions := lipgloss.JoinVertical(lipgloss.Left,
507+
lipgloss.JoinHorizontal(lipgloss.Left, "📊 ", keyStyle.Render("Match: "), formatValue(opt.Match)),
508+
lipgloss.JoinHorizontal(lipgloss.Left, "⚙️ ", keyStyle.Render("Filter: "), formatValue(opt.Filter)),
509+
)
510+
511+
// Plugin Options
512+
pluginValues := []string{}
513+
if opt.ActivePlugin {
514+
pluginValues = append(pluginValues, "active")
451515
}
452516
if opt.ReconPlugin {
453-
s.WriteString("recon enable; ")
517+
pluginValues = append(pluginValues, "recon")
454518
}
455-
if opt.RetryCount > 0 {
456-
s.WriteString("Retry Count: " + strconv.Itoa(opt.RetryCount))
519+
if opt.BakPlugin {
520+
pluginValues = append(pluginValues, "bak")
457521
}
458-
459-
if s.Len() > 0 {
460-
logs.Log.Important(s.String())
522+
if opt.CommonPlugin {
523+
pluginValues = append(pluginValues, "common")
461524
}
525+
if opt.CrawlPlugin {
526+
pluginValues = append(pluginValues, "crawl")
527+
}
528+
529+
pluginOptions := lipgloss.JoinVertical(lipgloss.Left,
530+
lipgloss.JoinHorizontal(lipgloss.Left, "🔎 ", keyStyle.Render("Extracts: "), formatValue(opt.Extracts)),
531+
lipgloss.JoinHorizontal(lipgloss.Left, "🔌 ", keyStyle.Render("Plugins: "), formatValue(strings.Join(pluginValues, ", "))),
532+
)
533+
534+
// Mode Options
535+
modeOptions := lipgloss.JoinVertical(lipgloss.Left,
536+
lipgloss.JoinHorizontal(lipgloss.Left, "🛑 ", keyStyle.Render("BlackStatus: "), formatValue(pkg.BlackStatus)),
537+
lipgloss.JoinHorizontal(lipgloss.Left, "✅ ", keyStyle.Render("WhiteStatus: "), formatValue(pkg.WhiteStatus)),
538+
lipgloss.JoinHorizontal(lipgloss.Left, "🔄 ", keyStyle.Render("FuzzyStatus: "), formatValue(pkg.FuzzyStatus)),
539+
lipgloss.JoinHorizontal(lipgloss.Left, "🔒 ", keyStyle.Render("UniqueStatus: "), formatValue(pkg.UniqueStatus)),
540+
lipgloss.JoinHorizontal(lipgloss.Left, "🔑 ", keyStyle.Render("Unique: "), formatValue(opt.Unique)),
541+
)
542+
543+
// Misc Options
544+
miscOptions := lipgloss.JoinVertical(lipgloss.Left,
545+
lipgloss.JoinHorizontal(lipgloss.Left, "⏱ ", keyStyle.Render("Timeout: "), formatValue(opt.Timeout)),
546+
lipgloss.JoinHorizontal(lipgloss.Left, "📈 ", keyStyle.Render("PoolSize: "), formatValue(opt.PoolSize)),
547+
lipgloss.JoinHorizontal(lipgloss.Left, "🧵 ", keyStyle.Render("Threads: "), formatValue(opt.Threads)),
548+
lipgloss.JoinHorizontal(lipgloss.Left, "🌍 ", keyStyle.Render("Proxy: "), formatValue(opt.Proxy)),
549+
)
550+
551+
// 将所有内容拼接在一起
552+
content := lipgloss.JoinVertical(lipgloss.Left,
553+
inputOptions,
554+
outputOptions,
555+
pluginOptions,
556+
modeOptions,
557+
miscOptions,
558+
)
559+
560+
// 使用正确的方式添加 padding,并居中显示内容
561+
contentWithPadding := lipgloss.NewStyle().PaddingLeft(padding).Render(content)
562+
563+
// 使用 Place 方法来将整个内容居中显示
564+
return lipgloss.Place(panelWidth+padding*2, 0, lipgloss.Center, lipgloss.Center,
565+
lipgloss.JoinVertical(lipgloss.Center,
566+
divider, // 顶部分割线
567+
contentWithPadding,
568+
divider, // 底部分割线
569+
),
570+
)
462571
}
463572

464573
func (opt *Option) BuildPlugin(r *Runner) error {
@@ -501,7 +610,6 @@ func (opt *Option) BuildPlugin(r *Runner) error {
501610
r.bruteMod = true
502611
}
503612

504-
opt.PrintPlugin()
505613
if r.bruteMod {
506614
logs.Log.Important("enabling brute mod, because of enabled brute plugin")
507615
}
@@ -670,7 +778,6 @@ func (opt *Option) BuildWords(r *Runner) error {
670778
})
671779
}
672780

673-
logs.Log.Importantf("%s mod, Loaded %d dictionaries, %d rules and %d decorators", opt.Mod, len(opt.Dictionaries), len(opt.Rules), len(r.Fns))
674781
return nil
675782
}
676783

internal/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ package internal
1414
// })
1515
// }
1616
//}
17+
18+
var ConfigTemplate = `
19+
-----------------------------------------------------------
20+
21+
-----------------------------------------------------------
22+
`

0 commit comments

Comments
 (0)