Debian Codegraph @

main.go

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 package main
2
3 import (
4 "fmt"
5 "io"
6 "os"
7 "strings"
8
9 "runtime"
10
11 "github.com/bettercap/bettercap/core"
12 "github.com/bettercap/bettercap/log"
13 "github.com/bettercap/bettercap/modules"
14 "github.com/bettercap/bettercap/session"
15
16 "github.com/evilsocket/islazy/str"
17 "github.com/evilsocket/islazy/tui"
18 )
19
20 func main() {
21 sess, err := session.New()
22 if err != nil {
23 fmt.Println(err)
24 os.Exit(1)
25 }
26 defer sess.Close()
27
28 if !tui.Effects() {
29 if *sess.Options.NoColors {
30 fmt.Printf("\n\nWARNING: Terminal colors have been disabled, view will be very limited.\n\n")
31 } else {
32 fmt.Printf("\n\nWARNING: This terminal does not support colors, view will be very limited.\n\n")
33 }
34 }
35
36 if *sess.Options.PrintVersion {
37 fmt.Printf("%s v%s (built for %s %s with %s)\n", core.Name, core.Version, runtime.GOOS, runtime.GOARCH, runtime.Version())
38 return
39 }
40
41 appName := fmt.Sprintf("%s v%s", core.Name, core.Version)
42 appBuild := fmt.Sprintf("(built for %s %s with %s)", runtime.GOOS, runtime.GOARCH, runtime.Version())
43
44 fmt.Printf("%s %s [type '%s' for a list of commands]\n\n", tui.Bold(appName), tui.Dim(appBuild), tui.Bold("help"))
45
46 // Load all modules
47 modules.LoadModules(sess)
48
49 if err = sess.Start(); err != nil {
50 log.Fatal("%s", err)
51 }
52
53 // Some modules are enabled by default in order
54 // to make the interactive session useful.
55 for _, modName := range str.Comma(*sess.Options.AutoStart) {
56 if err = sess.Run(modName + " on"); err != nil {
57 log.Fatal("error while starting module %s: %s", modName, err)
58 }
59 }
60
61 // Commands sent with -eval are used to set specific
62 // caplet parameters (i.e. arp.spoof.targets) via command
63 // line, therefore they need to be executed first otherwise
64 // modules might already be started.
65 for _, cmd := range session.ParseCommands(*sess.Options.Commands) {
66 if err = sess.Run(cmd); err != nil {
67 log.Error("error while running '%s': %s", tui.Bold(cmd), tui.Red(err.Error()))
68 }
69 }
70
71 // Then run the caplet if specified.
72 if *sess.Options.Caplet != "" {
73 if err = sess.RunCaplet(*sess.Options.Caplet); err != nil {
74 log.Error("error while running caplet %s: %s", tui.Bold(*sess.Options.Caplet), tui.Red(err.Error()))
75 }
76 }
77
78 // Eventually start the interactive session.
79 for sess.Active {
80 line, err := sess.ReadLine()
81 if err != nil {
82 if err == io.EOF || err.Error() == "Interrupt" {
83 if exitPrompt() {
84 sess.Run("exit")
85 os.Exit(0)
86 }
87 continue
88 } else {
89 log.Fatal("%s", err)
90 }
91 }
92
93 for _, cmd := range session.ParseCommands(line) {
94 if err = sess.Run(cmd); err != nil {
95 log.Error("%s", err)
96 }
97 }
98 }
99 }
100
101 func exitPrompt() bool {
102 var ans string
103 fmt.Printf("Are you sure you want to quit this session? y/n ")
104 fmt.Scan(&ans)
105
106 return strings.ToLower(ans) == "y"
107 }