Skip to content

Commit

Permalink
Release v4.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
j3ssie committed Nov 18, 2023
1 parent a753dec commit 71132e2
Show file tree
Hide file tree
Showing 22 changed files with 187 additions and 287 deletions.
3 changes: 1 addition & 2 deletions cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func init() {
}

func runCloud(cmd *cobra.Command, _ []string) error {
// DBInit()
utils.GoodF("%v %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), libs.VERSION, color.HiMagentaString(libs.AUTHOR))
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))
utils.InforF("Storing the log file to: %v", color.CyanString(options.LogFile))

// parse some arguments
Expand Down
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func runConfig(cmd *cobra.Command, args []string) error {
break
case "init":
if utils.FolderExists(fmt.Sprintf("%vcore", options.Env.RootFolder)) {
utils.GoodF("Look like you got properly setup.")
utils.TSPrintF("Look like you got properly setup.")
}
break
case "cred":
username, _ := cmd.Flags().GetString("user")
password, _ := cmd.Flags().GetString("pass")
utils.GoodF("Create new credentials %v:%v \n", username, password)
utils.TSPrintF("Create new credentials %v:%v \n", username, password)
break

case "reload":
Expand Down
2 changes: 1 addition & 1 deletion cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func init() {
}

func runScan(_ *cobra.Command, _ []string) error {
utils.GoodF("%v %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), libs.VERSION, color.HiMagentaString(libs.AUTHOR))
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))
utils.InforF("Storing the log file to: %v", color.CyanString(options.LogFile))

var wg sync.WaitGroup
Expand Down
2 changes: 1 addition & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func runServer(cmd *cobra.Command, _ []string) error {
host, _ := cmd.Flags().GetString("host")
port, _ := cmd.Flags().GetString("port")
options.Server.Bind = fmt.Sprintf("%v:%v", host, port)
utils.GoodF("%v %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), libs.VERSION, color.HiMagentaString(libs.AUTHOR))
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))
server.StartServer(options)
return nil
}
4 changes: 2 additions & 2 deletions core/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (r *Runner) BackupWorkspace() {

execution.Compress(dest, outputDir)
if utils.FileExists(dest) {
utils.GoodF("Backup workspace save at %s", color.HiMagentaString(dest))
utils.TSPrintF("Backup workspace save at %s", color.HiMagentaString(dest))
}
}

Expand Down Expand Up @@ -64,5 +64,5 @@ func ExtractBackup(src string, opt libs.Options) {
utils.MakeDir(dest)
}
execution.Decompress(dest, src)
utils.GoodF("Extracting the %v to %s", color.HiCyanString(target), color.HiMagentaString(dest))
utils.TSPrintF("Extracting the %v to %s", color.HiCyanString(target), color.HiMagentaString(dest))
}
1 change: 0 additions & 1 deletion core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func InitConfig(options *libs.Options) error {
if err := v.WriteConfigAs(options.ConfigFile); err != nil {
utils.ErrorF("Error writing config file: %s", err)
}

utils.InforF("Created a new configuration file at %s", color.HiCyanString(options.ConfigFile))
}

Expand Down
18 changes: 9 additions & 9 deletions core/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ func (r *Runner) RunModule(module libs.Module) {
// check if resume enable or not
if (r.Opt.Resume || module.Resume) && !module.Forced {
if CheckResume(module) {
utils.BlockF(module.Name, "Resume detected")
utils.TSPrintF("The %v module has resume", color.HiGreenString(module.Name))
return
}
}

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

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

// main part
// utils.BlockF(module.Name, "Begin executing primary tasks")
err := r.RunSteps(module.Steps)
if err != nil {
utils.BadBlockF(module.Name, fmt.Sprintf("got exit call"))
utils.BadBlockF(fmt.Sprintf("got an exit call"))
}

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

// print the reports file
utils.PrintLine()
printReports(module)

// estimate time
elapsedTime := time.Since(timeStart).Seconds()
utils.BlockF("Module-Ended", fmt.Sprintf("Elapsed Time for the module %v in %v", color.HiCyanString(module.Name), color.HiMagentaString("%vs", elapsedTime)))
utils.TSPrintF("The %v module finished within %v.", color.HiGreenString(module.Name), color.HiMagentaString("%vs", elapsedTime))

r.RunningTime += cast.ToInt(elapsedTime)
utils.PrintLine()

r.DBUpdateScan()
}

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

// checking required file
Expand Down
1 change: 0 additions & 1 deletion core/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ func ParseTarget(raw string) map[string]string {
if err != nil {
return target
}
// fmt.Println("parse again")
}
var hostname string
var query string
Expand Down
3 changes: 2 additions & 1 deletion core/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const (
CleanJSONDnsx = "CleanJSONDnsx"
CleanWebanalyze = "CleanWebanalyze"
CleanArjun = "CleanArjun"
GenNucleiReport = "GenNucleiReport"
CleanJSONHttpx = "CleanJSONHttpx"
CleanFFUFJson = "CleanFFUFJson"
GenNucleiReport = "GenNucleiReport"
PrintCSV = "PrintCSV"
)

const (
Expand Down
85 changes: 51 additions & 34 deletions core/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,47 @@ func (r *Runner) PrepareRoutine() {
}

// PrepareParams prepare global params
func (r *Runner) ParamsFromCLI() {
// more params from -p flag which will override everything
if len(r.Opt.Scan.Params) > 0 {
params := ParseParams(r.Opt.Scan.Params)
if len(params) > 0 {
for k, v := range params {
v = ResolveData(v, r.Params)
r.Params[k] = v
}
}
}

// parsing params from a file with should have the format
// param1: value1
// param2: value2
if len(r.Opt.Scan.ParamsFile) > 0 {
var params map[string]string
yamlFile, err := os.ReadFile(r.Opt.Scan.ParamsFile)
if err != nil {
utils.ErrorF("YAML parsing err: %v -- #%v ", r.Opt.Scan.ParamsFile, err)
return
}
err = yaml.Unmarshal(yamlFile, &params)
if err != nil {
utils.ErrorF("Error unmarshal: %v -- %v", params, err)
return
}
if len(params) > 0 {
for k, v := range params {
v = ResolveData(v, r.Params)
r.Params[k] = v
}
}
}
}
func (r *Runner) PrepareParams() {
r.Params = r.Target

// parse from CLI first to avoid blank param if it use in the module file
r.ParamsFromCLI()

// looking for more params from each module
for _, routine := range r.Routines {
for _, module := range routine.ParsedModules {
Expand All @@ -221,42 +259,21 @@ func (r *Runner) PrepareParams() {
}
}
}
}
}

if len(r.Opt.Scan.ParamsFile) > 0 {
var params map[string]string
yamlFile, err := os.ReadFile(r.Opt.Scan.ParamsFile)
if err != nil {
utils.ErrorF("YAML parsing err: %v -- #%v ", r.Opt.Scan.ParamsFile, err)
return
}
err = yaml.Unmarshal(yamlFile, &params)
if err != nil {
utils.ErrorF("Error unmarshal: %v -- %v", params, err)
return
}
if len(params) > 0 {
for k, v := range params {
v = ResolveData(v, r.Params)
r.Params[k] = v
}
}
}
// more params from -p flag which will override everything
r.ParamsFromCLI()

// more params from -p flag which will override everything
if len(r.Opt.Scan.Params) > 0 {
params := ParseParams(r.Opt.Scan.Params)
if len(params) > 0 {
for k, v := range params {
v = ResolveData(v, r.Params)
r.Params[k] = v
}
}
}
if r.Opt.Debug {
utils.DebugF("Loading %v parameters", color.HiMagentaString("%v", len(r.Params)))
var allParams []string
for k, v := range r.Params {
allParams = append(allParams, fmt.Sprintf("%v=%v", color.HiGreenString(k), color.HiWhiteString(v)))
}
utils.DebugF("All parameters value: %v", strings.Join(allParams, color.HiMagentaString(", ")))
}

r.ResolveRoutine()

}

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

utils.InforF("Running the routine %v on %v", color.HiYellowString(r.RoutineName), color.CyanString(r.Input))
utils.TSPrintF("Running the routine %v on %v", color.HiYellowString(r.RoutineName), color.CyanString(r.Input))
utils.InforF("Detailed runtime file can be found on %v", color.CyanString(r.RuntimeFile))
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)

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

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

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

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

Expand Down
13 changes: 9 additions & 4 deletions core/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ func (r *Runner) LoadScripts() string {
filename := call.Argument(0).String()
utils.InforF("Showing the content of: %v", color.HiCyanString(filename))
utils.Cat(filename)
result, err := vm.ToValue(true)
if err != nil {
return otto.Value{}
}
result, _ := vm.ToValue(true)
return result
})

vm.Set(PrintCSV, func(call otto.FunctionCall) otto.Value {
filename := call.Argument(0).String()
utils.InforF("Beautify CSV print the content of: %v", color.HiCyanString(filename))
execution.PrintCSV(filename)
result, _ := vm.ToValue(true)
return result
})

Expand Down
16 changes: 12 additions & 4 deletions core/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (r *Runner) RunModulesWithTimeout(timeoutRaw string, module libs.Module, op
utils.DebugF("Module done")
return
case <-time.After(time.Duration(timeout) * time.Second):
utils.BadBlockF("timeout", fmt.Sprintf("Module got timeout after %v", color.HiMagentaString(timeoutRaw)))
utils.BadBlockF(fmt.Sprintf("Module got timeout after %v", color.HiMagentaString(timeoutRaw)))
}
return
}
Expand Down Expand Up @@ -70,23 +70,31 @@ func ResolveReports(module libs.Module, params map[string]string) libs.Module {
return module
}

// print all report
// print all report
func printReports(module libs.Module) {
var files []string
files = append(files, module.Report.Final...)
files = append(files, module.Report.Noti...)
files = append(files, module.Report.Diff...)

reports := funk.UniqString(files)
utils.BlockF("Report", color.HiCyanString("List of reports generated by the %v module", color.HiGreenString(module.Name)))
if len(reports) == 0 {
utils.DebugF("No report generated by the %v module", module.Name)
return
}

utils.PrintLine()
utils.TSPrintF("List of %v reports generated by the %v module", color.HiMagentaString("%v", len(reports)), color.HiGreenString(module.Name))
for _, report := range reports {
if !utils.FileExists(report) && utils.EmptyFile(report, 0) {
if !utils.FolderExists(report) && utils.EmptyDir(report) {
continue
}
}
utils.BlockF("report-file", report)
utils.TSPrintF("report file: %v", report)
}
utils.PrintLine()

}

// CheckRequired check if required file exist or not
Expand Down
45 changes: 45 additions & 0 deletions execution/beautify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package execution

import (
"encoding/csv"
"os"

"github.com/j3ssie/osmedeus/utils"
"github.com/olekukonko/tablewriter"
)

func PrintCSV(filename string) {
filename = utils.NormalizePath(filename)
if !utils.FileExists(filename) {
return
}

// Open the CSV file
file, err := os.Open(filename)
if err != nil {
utils.ErrorF("%v", err)
return
}
defer file.Close()
// Create a new CSV reader
reader := csv.NewReader(file)
reader.LazyQuotes = true

// Read all CSV records
records, err := reader.ReadAll()
if err != nil {
utils.ErrorF("%v", err)
return
}

// Create a new table
table := tablewriter.NewWriter(os.Stdout)
for _, record := range records {
table.Append(record)
}
table.SetRowLine(false)
table.SetBorders(tablewriter.Border{Left: false, Top: true, Right: false, Bottom: true})
table.SetColWidth(100)
table.SetAutoWrapText(true)
table.Render()
}
Loading

0 comments on commit 71132e2

Please sign in to comment.