Skip to content

Commit 71132e2

Browse files
committed
Release v4.6.2
1 parent a753dec commit 71132e2

22 files changed

+187
-287
lines changed

cmd/cloud.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ func init() {
6262
}
6363

6464
func runCloud(cmd *cobra.Command, _ []string) error {
65-
// DBInit()
66-
utils.GoodF("%v %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), libs.VERSION, color.HiMagentaString(libs.AUTHOR))
65+
utils.GoodF("Using the %v Engine %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), color.HiCyanString(libs.VERSION), color.HiMagentaString(libs.AUTHOR))
6766
utils.InforF("Storing the log file to: %v", color.CyanString(options.LogFile))
6867

6968
// parse some arguments

cmd/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ func runConfig(cmd *cobra.Command, args []string) error {
5555
break
5656
case "init":
5757
if utils.FolderExists(fmt.Sprintf("%vcore", options.Env.RootFolder)) {
58-
utils.GoodF("Look like you got properly setup.")
58+
utils.TSPrintF("Look like you got properly setup.")
5959
}
6060
break
6161
case "cred":
6262
username, _ := cmd.Flags().GetString("user")
6363
password, _ := cmd.Flags().GetString("pass")
64-
utils.GoodF("Create new credentials %v:%v \n", username, password)
64+
utils.TSPrintF("Create new credentials %v:%v \n", username, password)
6565
break
6666

6767
case "reload":

cmd/scan.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func init() {
3434
}
3535

3636
func runScan(_ *cobra.Command, _ []string) error {
37-
utils.GoodF("%v %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), libs.VERSION, color.HiMagentaString(libs.AUTHOR))
37+
utils.GoodF("Using the %v Engine %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), color.HiCyanString(libs.VERSION), color.HiMagentaString(libs.AUTHOR))
3838
utils.InforF("Storing the log file to: %v", color.CyanString(options.LogFile))
3939

4040
var wg sync.WaitGroup

cmd/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func runServer(cmd *cobra.Command, _ []string) error {
4343
host, _ := cmd.Flags().GetString("host")
4444
port, _ := cmd.Flags().GetString("port")
4545
options.Server.Bind = fmt.Sprintf("%v:%v", host, port)
46-
utils.GoodF("%v %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), libs.VERSION, color.HiMagentaString(libs.AUTHOR))
46+
utils.GoodF("Using the %v Engine %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), color.HiCyanString(libs.VERSION), color.HiMagentaString(libs.AUTHOR))
4747
server.StartServer(options)
4848
return nil
4949
}

core/backup.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (r *Runner) BackupWorkspace() {
2525

2626
execution.Compress(dest, outputDir)
2727
if utils.FileExists(dest) {
28-
utils.GoodF("Backup workspace save at %s", color.HiMagentaString(dest))
28+
utils.TSPrintF("Backup workspace save at %s", color.HiMagentaString(dest))
2929
}
3030
}
3131

@@ -64,5 +64,5 @@ func ExtractBackup(src string, opt libs.Options) {
6464
utils.MakeDir(dest)
6565
}
6666
execution.Decompress(dest, src)
67-
utils.GoodF("Extracting the %v to %s", color.HiCyanString(target), color.HiMagentaString(dest))
67+
utils.TSPrintF("Extracting the %v to %s", color.HiCyanString(target), color.HiMagentaString(dest))
6868
}

core/config.go

-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func InitConfig(options *libs.Options) error {
128128
if err := v.WriteConfigAs(options.ConfigFile); err != nil {
129129
utils.ErrorF("Error writing config file: %s", err)
130130
}
131-
132131
utils.InforF("Created a new configuration file at %s", color.HiCyanString(options.ConfigFile))
133132
}
134133

core/module.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ func (r *Runner) RunModule(module libs.Module) {
2525
// check if resume enable or not
2626
if (r.Opt.Resume || module.Resume) && !module.Forced {
2727
if CheckResume(module) {
28-
utils.BlockF(module.Name, "Resume detected")
28+
utils.TSPrintF("The %v module has resume", color.HiGreenString(module.Name))
2929
return
3030
}
3131
}
3232

3333
r.CurrentModule = module.Name
3434
timeStart := time.Now()
35-
utils.BlockF("Module-Started", fmt.Sprintf("%v - %v", module.Name, module.Desc))
35+
utils.TSPrintF("The %v module has begun", color.HiGreenString(module.Name))
36+
utils.TSPrintF("The objective of %v module: %v", color.HiGreenString(module.Name), color.HiCyanString(module.Desc))
3637

3738
// create report record first because I don't want to wait for them to show up in UI until the module done
3839
r.DBNewReports(module)
@@ -44,10 +45,9 @@ func (r *Runner) RunModule(module libs.Module) {
4445
}
4546

4647
// main part
47-
// utils.BlockF(module.Name, "Begin executing primary tasks")
4848
err := r.RunSteps(module.Steps)
4949
if err != nil {
50-
utils.BadBlockF(module.Name, fmt.Sprintf("got exit call"))
50+
utils.BadBlockF(fmt.Sprintf("got an exit call"))
5151
}
5252

5353
// post-run
@@ -57,14 +57,14 @@ func (r *Runner) RunModule(module libs.Module) {
5757
}
5858

5959
// print the reports file
60-
utils.PrintLine()
6160
printReports(module)
6261

6362
// estimate time
6463
elapsedTime := time.Since(timeStart).Seconds()
65-
utils.BlockF("Module-Ended", fmt.Sprintf("Elapsed Time for the module %v in %v", color.HiCyanString(module.Name), color.HiMagentaString("%vs", elapsedTime)))
64+
utils.TSPrintF("The %v module finished within %v.", color.HiGreenString(module.Name), color.HiMagentaString("%vs", elapsedTime))
65+
6666
r.RunningTime += cast.ToInt(elapsedTime)
67-
utils.PrintLine()
67+
6868
r.DBUpdateScan()
6969
}
7070

@@ -111,7 +111,7 @@ func (r *Runner) RunScriptsWithTimeOut(timeoutRaw string, scripts []string) stri
111111
utils.DebugF("Scripts done")
112112
return ""
113113
case <-time.After(time.Duration(timeout) * time.Second):
114-
utils.BadBlockF("timeout", fmt.Sprintf("Scripts got timeout after %v", color.HiMagentaString(timeoutRaw)))
114+
utils.BadBlockF(fmt.Sprintf("Scripts got timeout after %v", color.HiMagentaString(timeoutRaw)))
115115
}
116116
return ""
117117
}
@@ -171,7 +171,7 @@ func (r *Runner) RunStepWithTimeout(timeout int, step libs.Step) (out string, er
171171
func (r *Runner) RunStep(step libs.Step) (string, error) {
172172
var output string
173173
if step.Label != "" {
174-
utils.BlockF("Step", fmt.Sprintf("Initiating Step %v", color.HiGreenString(step.Label)))
174+
utils.TSPrintF("Initiating Step %v", color.HiGreenString(step.Label))
175175
}
176176

177177
// checking required file

core/parse.go

-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ func ParseTarget(raw string) map[string]string {
244244
if err != nil {
245245
return target
246246
}
247-
// fmt.Println("parse again")
248247
}
249248
var hostname string
250249
var query string

core/reference.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ const (
1212
CleanJSONDnsx = "CleanJSONDnsx"
1313
CleanWebanalyze = "CleanWebanalyze"
1414
CleanArjun = "CleanArjun"
15-
GenNucleiReport = "GenNucleiReport"
1615
CleanJSONHttpx = "CleanJSONHttpx"
1716
CleanFFUFJson = "CleanFFUFJson"
17+
GenNucleiReport = "GenNucleiReport"
18+
PrintCSV = "PrintCSV"
1819
)
1920

2021
const (

core/runner.go

+51-34
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,47 @@ func (r *Runner) PrepareRoutine() {
196196
}
197197

198198
// PrepareParams prepare global params
199+
func (r *Runner) ParamsFromCLI() {
200+
// more params from -p flag which will override everything
201+
if len(r.Opt.Scan.Params) > 0 {
202+
params := ParseParams(r.Opt.Scan.Params)
203+
if len(params) > 0 {
204+
for k, v := range params {
205+
v = ResolveData(v, r.Params)
206+
r.Params[k] = v
207+
}
208+
}
209+
}
210+
211+
// parsing params from a file with should have the format
212+
// param1: value1
213+
// param2: value2
214+
if len(r.Opt.Scan.ParamsFile) > 0 {
215+
var params map[string]string
216+
yamlFile, err := os.ReadFile(r.Opt.Scan.ParamsFile)
217+
if err != nil {
218+
utils.ErrorF("YAML parsing err: %v -- #%v ", r.Opt.Scan.ParamsFile, err)
219+
return
220+
}
221+
err = yaml.Unmarshal(yamlFile, &params)
222+
if err != nil {
223+
utils.ErrorF("Error unmarshal: %v -- %v", params, err)
224+
return
225+
}
226+
if len(params) > 0 {
227+
for k, v := range params {
228+
v = ResolveData(v, r.Params)
229+
r.Params[k] = v
230+
}
231+
}
232+
}
233+
}
199234
func (r *Runner) PrepareParams() {
200235
r.Params = r.Target
201236

237+
// parse from CLI first to avoid blank param if it use in the module file
238+
r.ParamsFromCLI()
239+
202240
// looking for more params from each module
203241
for _, routine := range r.Routines {
204242
for _, module := range routine.ParsedModules {
@@ -221,42 +259,21 @@ func (r *Runner) PrepareParams() {
221259
}
222260
}
223261
}
262+
}
263+
}
224264

225-
if len(r.Opt.Scan.ParamsFile) > 0 {
226-
var params map[string]string
227-
yamlFile, err := os.ReadFile(r.Opt.Scan.ParamsFile)
228-
if err != nil {
229-
utils.ErrorF("YAML parsing err: %v -- #%v ", r.Opt.Scan.ParamsFile, err)
230-
return
231-
}
232-
err = yaml.Unmarshal(yamlFile, &params)
233-
if err != nil {
234-
utils.ErrorF("Error unmarshal: %v -- %v", params, err)
235-
return
236-
}
237-
if len(params) > 0 {
238-
for k, v := range params {
239-
v = ResolveData(v, r.Params)
240-
r.Params[k] = v
241-
}
242-
}
243-
}
265+
// more params from -p flag which will override everything
266+
r.ParamsFromCLI()
244267

245-
// more params from -p flag which will override everything
246-
if len(r.Opt.Scan.Params) > 0 {
247-
params := ParseParams(r.Opt.Scan.Params)
248-
if len(params) > 0 {
249-
for k, v := range params {
250-
v = ResolveData(v, r.Params)
251-
r.Params[k] = v
252-
}
253-
}
254-
}
268+
if r.Opt.Debug {
269+
utils.DebugF("Loading %v parameters", color.HiMagentaString("%v", len(r.Params)))
270+
var allParams []string
271+
for k, v := range r.Params {
272+
allParams = append(allParams, fmt.Sprintf("%v=%v", color.HiGreenString(k), color.HiWhiteString(v)))
255273
}
274+
utils.DebugF("All parameters value: %v", strings.Join(allParams, color.HiMagentaString(", ")))
256275
}
257-
258276
r.ResolveRoutine()
259-
260277
}
261278

262279
// ResolveRoutine resolve the module name first
@@ -377,7 +394,7 @@ func (r *Runner) Start() {
377394
r.WorkspaceFolder = r.Target["Output"]
378395
os.Remove(r.DoneFile)
379396

380-
utils.InforF("Running the routine %v on %v", color.HiYellowString(r.RoutineName), color.CyanString(r.Input))
397+
utils.TSPrintF("Running the routine %v on %v", color.HiYellowString(r.RoutineName), color.CyanString(r.Input))
381398
utils.InforF("Detailed runtime file can be found on %v", color.CyanString(r.RuntimeFile))
382399
execution.TeleSendMess(r.Opt, fmt.Sprintf("%s -- Start new scan: %s -- %s", r.Opt.Noti.ClientName, r.Opt.Scan.Flow, r.Target["Workspace"]), "#status", false)
383400

@@ -393,7 +410,7 @@ func (r *Runner) Start() {
393410
/////
394411

395412
r.DBDoneScan()
396-
utils.BlockF("Finished", fmt.Sprintf("The scan for %v was completed within %v", color.HiCyanString(r.Input), color.HiMagentaString("%vs", r.RunningTime)))
413+
utils.TSPrintF(fmt.Sprintf("The scan for %v was completed within %v", color.HiCyanString(r.Input), color.HiMagentaString("%vs", r.RunningTime)))
397414

398415
if r.Opt.EnableBackup {
399416
r.BackupWorkspace()
@@ -419,7 +436,7 @@ func (r *Runner) RunRoutine(modules []libs.Module) {
419436

420437
for _, module := range modules {
421438
if funk.ContainsString(r.Opt.Exclude, module.Name) {
422-
utils.BadBlockF("Module-Excluded", fmt.Sprintf("Module %v has been excluded", color.CyanString(module.Name)))
439+
utils.BadBlockF(fmt.Sprintf("Module %v has been excluded", color.CyanString(module.Name)))
423440
continue
424441
}
425442

core/runtime.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,15 @@ func (r *Runner) LoadScripts() string {
125125
filename := call.Argument(0).String()
126126
utils.InforF("Showing the content of: %v", color.HiCyanString(filename))
127127
utils.Cat(filename)
128-
result, err := vm.ToValue(true)
129-
if err != nil {
130-
return otto.Value{}
131-
}
128+
result, _ := vm.ToValue(true)
129+
return result
130+
})
131+
132+
vm.Set(PrintCSV, func(call otto.FunctionCall) otto.Value {
133+
filename := call.Argument(0).String()
134+
utils.InforF("Beautify CSV print the content of: %v", color.HiCyanString(filename))
135+
execution.PrintCSV(filename)
136+
result, _ := vm.ToValue(true)
132137
return result
133138
})
134139

core/step.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (r *Runner) RunModulesWithTimeout(timeoutRaw string, module libs.Module, op
3232
utils.DebugF("Module done")
3333
return
3434
case <-time.After(time.Duration(timeout) * time.Second):
35-
utils.BadBlockF("timeout", fmt.Sprintf("Module got timeout after %v", color.HiMagentaString(timeoutRaw)))
35+
utils.BadBlockF(fmt.Sprintf("Module got timeout after %v", color.HiMagentaString(timeoutRaw)))
3636
}
3737
return
3838
}
@@ -70,23 +70,31 @@ func ResolveReports(module libs.Module, params map[string]string) libs.Module {
7070
return module
7171
}
7272

73-
// print all report
73+
// print all report
7474
func printReports(module libs.Module) {
7575
var files []string
7676
files = append(files, module.Report.Final...)
7777
files = append(files, module.Report.Noti...)
7878
files = append(files, module.Report.Diff...)
7979

8080
reports := funk.UniqString(files)
81-
utils.BlockF("Report", color.HiCyanString("List of reports generated by the %v module", color.HiGreenString(module.Name)))
81+
if len(reports) == 0 {
82+
utils.DebugF("No report generated by the %v module", module.Name)
83+
return
84+
}
85+
86+
utils.PrintLine()
87+
utils.TSPrintF("List of %v reports generated by the %v module", color.HiMagentaString("%v", len(reports)), color.HiGreenString(module.Name))
8288
for _, report := range reports {
8389
if !utils.FileExists(report) && utils.EmptyFile(report, 0) {
8490
if !utils.FolderExists(report) && utils.EmptyDir(report) {
8591
continue
8692
}
8793
}
88-
utils.BlockF("report-file", report)
94+
utils.TSPrintF("report file: %v", report)
8995
}
96+
utils.PrintLine()
97+
9098
}
9199

92100
// CheckRequired check if required file exist or not

execution/beautify.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package execution
2+
3+
import (
4+
"encoding/csv"
5+
"os"
6+
7+
"github.com/j3ssie/osmedeus/utils"
8+
"github.com/olekukonko/tablewriter"
9+
)
10+
11+
func PrintCSV(filename string) {
12+
filename = utils.NormalizePath(filename)
13+
if !utils.FileExists(filename) {
14+
return
15+
}
16+
17+
// Open the CSV file
18+
file, err := os.Open(filename)
19+
if err != nil {
20+
utils.ErrorF("%v", err)
21+
return
22+
}
23+
defer file.Close()
24+
// Create a new CSV reader
25+
reader := csv.NewReader(file)
26+
reader.LazyQuotes = true
27+
28+
// Read all CSV records
29+
records, err := reader.ReadAll()
30+
if err != nil {
31+
utils.ErrorF("%v", err)
32+
return
33+
}
34+
35+
// Create a new table
36+
table := tablewriter.NewWriter(os.Stdout)
37+
for _, record := range records {
38+
table.Append(record)
39+
}
40+
table.SetRowLine(false)
41+
table.SetBorders(tablewriter.Border{Left: false, Top: true, Right: false, Bottom: true})
42+
table.SetColWidth(100)
43+
table.SetAutoWrapText(true)
44+
table.Render()
45+
}

0 commit comments

Comments
 (0)