forked from jaeles-project/jaeles
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
121 lines (109 loc) · 3.83 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package core
import (
"bytes"
"fmt"
"github.com/Jeffail/gabs/v2"
"github.com/ARPSyndicate/jaeles/libs"
"github.com/ARPSyndicate/jaeles/utils"
"github.com/spf13/viper"
"io/ioutil"
"os"
"path"
"path/filepath"
)
// InitConfig init config
func InitConfig(options *libs.Options) {
options.RootFolder = utils.NormalizePath(options.RootFolder)
options.Server.DBPath = path.Join(options.RootFolder, "sqlite3.db")
// init new root folder
if !utils.FolderExists(options.RootFolder) {
utils.InforF("Init new config at %v", options.RootFolder)
os.MkdirAll(options.RootFolder, 0750)
// cloning default repo
UpdatePlugins(*options)
UpdateSignature(*options)
}
configPath := path.Join(options.RootFolder, "config.yaml")
v := viper.New()
v.AddConfigPath(options.RootFolder)
v.SetConfigName("config")
v.SetConfigType("yaml")
if !utils.FileExists(configPath) {
utils.InforF("Write new config to: %v", configPath)
// save default config if not exist
bind := "http://127.0.0.1:5000"
v.SetDefault("defaultSign", "*")
v.SetDefault("cors", "*")
// default credential
v.SetDefault("username", "jaeles")
v.SetDefault("password", utils.GenHash(utils.GetTS())[:10])
v.SetDefault("secret", utils.GenHash(utils.GetTS()))
v.SetDefault("bind", bind)
v.WriteConfigAs(configPath)
} else {
if options.Debug {
utils.InforF("Load config from: %v", configPath)
}
b, _ := ioutil.ReadFile(configPath)
v.ReadConfig(bytes.NewBuffer(b))
}
// WARNING: change me if you really want to deploy on remote server
// allow all origin
options.Server.Cors = v.GetString("cors")
options.Server.JWTSecret = v.GetString("secret")
options.Server.Username = v.GetString("username")
options.Server.Password = v.GetString("password")
// store default credentials for Burp plugin
burpConfigPath := path.Join(options.RootFolder, "burp.json")
if !utils.FileExists(burpConfigPath) {
jsonObj := gabs.New()
jsonObj.Set("", "JWT")
jsonObj.Set(v.GetString("username"), "username")
jsonObj.Set(v.GetString("password"), "password")
bind := v.GetString("bind")
if bind == "" {
bind = "http://127.0.0.1:5000"
}
jsonObj.Set(fmt.Sprintf("http://%v/api/parse", bind), "endpoint")
utils.WriteToFile(burpConfigPath, jsonObj.String())
if options.Verbose {
utils.InforF("Store default credentials for client at: %v", burpConfigPath)
}
}
// set some default config
options.PassiveFolder = path.Join(utils.NormalizePath(options.RootFolder), "passives")
options.ResourcesFolder = path.Join(utils.NormalizePath(options.RootFolder), "resources")
options.ThirdPartyFolder = path.Join(utils.NormalizePath(options.RootFolder), "thirdparty")
// create output folder
var err error
err = os.MkdirAll(options.Output, 0750)
if err != nil && options.NoOutput == false {
fmt.Fprintf(os.Stderr, "failed to create output directory: %s\n", err)
os.Exit(1)
}
if options.SummaryOutput == "" {
options.SummaryOutput = path.Join(options.Output, "jaeles-summary.txt")
}
if options.SummaryVuln == "" {
options.SummaryVuln = path.Join(options.Output, "vuln-summary.txt")
}
if options.PassiveOutput == "" {
passiveOut := "passive-" + path.Base(options.Output)
options.PassiveOutput = path.Join(filepath.Dir(path.Clean(options.Output)), passiveOut)
}
if options.PassiveSummary == "" {
options.PassiveSummary = path.Join(options.PassiveOutput, "jaeles-passive-summary.txt")
}
dbSize := utils.GetFileSize(options.Server.DBPath)
if dbSize > 5.0 {
utils.WarningF("Your Database size look very big: %vGB", fmt.Sprintf("%.2f", dbSize))
utils.WarningF("Consider clean your db with this command: 'jaeles config -a clear' or just remove your '~/.jaeles/'")
}
utils.InforF("Summary output: %v", options.SummaryOutput)
if options.ChunkRun {
if options.ChunkDir == "" {
options.ChunkDir = path.Join(os.TempDir(), "jaeles-chunk-data")
}
os.MkdirAll(options.ChunkDir, 0755)
}
}