Skip to content

Commit

Permalink
Update some usage message
Browse files Browse the repository at this point in the history
  • Loading branch information
j3ssie committed Feb 16, 2023
1 parent 738cc68 commit c6bb0c4
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 43 deletions.
7 changes: 6 additions & 1 deletion cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ func init() {
cloudCmd.Flags().IntVar(&options.Cloud.Retry, "retry", 10, "Number of retry when command is error")
cloudCmd.SetHelpFunc(CloudHelp)
RootCmd.AddCommand(cloudCmd)

cloudCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

func runCloud(cmd *cobra.Command, _ []string) error {
Expand Down
9 changes: 8 additions & 1 deletion cmd/exec.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cmd

import (
"os"

"github.com/j3ssie/osmedeus/core"
"github.com/j3ssie/osmedeus/utils"
"github.com/spf13/cobra"
"os"
)

func init() {
Expand All @@ -18,6 +19,12 @@ func init() {
execCmd.Flags().String("script", "", "Scripts to run (Multiple -s flags are accepted)")
execCmd.Flags().StringP("scriptFile", "S", "", "File contain list of scripts")
RootCmd.AddCommand(execCmd)
execCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

func runExec(cmd *cobra.Command, _ []string) error {
Expand Down
15 changes: 11 additions & 4 deletions cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package cmd

import (
"fmt"
"os"
"path"
"sort"

"github.com/fatih/color"
"github.com/j3ssie/osmedeus/core"
"github.com/j3ssie/osmedeus/execution"
"github.com/j3ssie/osmedeus/libs"
"github.com/j3ssie/osmedeus/utils"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"os"
"path"
"sort"
)

func init() {
Expand All @@ -23,6 +24,12 @@ func init() {
RunE: runHealth,
}
RootCmd.AddCommand(healthCmd)
healthCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

func runHealth(_ *cobra.Command, args []string) error {
Expand Down Expand Up @@ -79,7 +86,7 @@ func runHealth(_ *cobra.Command, args []string) error {
fmt.Printf("‼️ There is might be something wrong with your workflow setup: %v\n", err)
return nil
}
fmt.Printf(color.GreenString("\n🦾 It’s all good. Happy Hacking 🦾\n"))
fmt.Printf(color.GreenString("\n🦾 Everything is in order. Happy Hacking 🦾\n"))
return nil
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func init() {
providerCmd.AddCommand(providerBuild)
providerCmd.SetHelpFunc(CloudHelp)
RootCmd.AddCommand(providerCmd)
providerCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

func runCloudHealth(_ *cobra.Command, _ []string) error {
Expand Down
7 changes: 7 additions & 0 deletions cmd/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"
"path"
"strings"

Expand All @@ -27,6 +28,12 @@ func init() {
queueCmd.PersistentFlags().StringVar(&options.Queue.RawCommand, "cmd", "", "Raw Command to run")
queueCmd.SetHelpFunc(QueueHelp)
RootCmd.AddCommand(queueCmd)
queueCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

func runQueue(_ *cobra.Command, _ []string) error {
Expand Down
7 changes: 7 additions & 0 deletions cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"strings"
Expand Down Expand Up @@ -54,6 +55,12 @@ func init() {
reportCmd.PersistentFlags().BoolVar(&options.Report.Static, "static", false, "Show report file with Prefix Static")
reportCmd.SetHelpFunc(ReportHelp)
RootCmd.AddCommand(reportCmd)
reportCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

func runReportList(_ *cobra.Command, _ []string) error {
Expand Down
12 changes: 10 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package cmd
import (
"bufio"
"fmt"
"github.com/j3ssie/osmedeus/database"
"os"
"strings"

"github.com/j3ssie/osmedeus/database"

"github.com/j3ssie/osmedeus/core"
"github.com/j3ssie/osmedeus/libs"
"github.com/j3ssie/osmedeus/utils"
Expand All @@ -19,7 +20,7 @@ var options = libs.Options{}
//var DB *gorm.DB

var RootCmd = &cobra.Command{
Use: fmt.Sprintf("%s", libs.BINARY),
Use: libs.BINARY,
Short: fmt.Sprintf("%s - %s", libs.BINARY, libs.DESC),
Long: core.Banner(),
}
Expand Down Expand Up @@ -72,6 +73,7 @@ func init() {
RootCmd.PersistentFlags().BoolVarP(&options.Resume, "resume", "R", false, "Enable Resume mode to skip modules that have already been finished")
RootCmd.PersistentFlags().BoolVar(&options.Debug, "debug", false, "Enable Debug output")
RootCmd.PersistentFlags().BoolVarP(&options.Quite, "quite", "q", false, "Show only essential information")
RootCmd.PersistentFlags().BoolVar(&options.FullHelp, "hh", false, "Show full help message")
RootCmd.PersistentFlags().BoolVar(&options.WildCardCheck, "ww", false, "Check for wildcard target")
RootCmd.PersistentFlags().BoolVar(&options.DisableValidateInput, "nv", false, "Disable Validate Input")
RootCmd.PersistentFlags().BoolVar(&options.Update.NoUpdate, "nu", false, "Disable Update options")
Expand Down Expand Up @@ -101,6 +103,12 @@ func init() {

RootCmd.SetHelpFunc(RootHelp)
cobra.OnInitialize(initConfig)
RootCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

// initConfig reads in config file and ENV variables if set.
Expand Down
7 changes: 7 additions & 0 deletions cmd/scan.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"os"
"strings"
"sync"

Expand All @@ -24,6 +25,12 @@ func init() {

scanCmd.SetHelpFunc(ScanHelp)
RootCmd.AddCommand(scanCmd)
scanCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

func runScan(_ *cobra.Command, _ []string) error {
Expand Down
7 changes: 7 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"

"github.com/j3ssie/osmedeus/core"
"github.com/j3ssie/osmedeus/server"
Expand All @@ -23,6 +24,12 @@ func init() {
serverCmd.Flags().BoolVar(&options.Server.PreFork, "prefork", false, "Enable Prefork mode for the api server")
serverCmd.Flags().BoolVarP(&options.Server.NoAuthen, "no-auth", "A", false, "Disable authentication for the api server")
RootCmd.AddCommand(serverCmd)
serverCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

func runServer(cmd *cobra.Command, _ []string) error {
Expand Down
8 changes: 8 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"os"

"github.com/j3ssie/osmedeus/core"
"github.com/j3ssie/osmedeus/utils"
"github.com/spf13/cobra"
Expand All @@ -20,6 +22,12 @@ func init() {
// generate update meta data
updateCmd.Flags().StringVar(&options.Update.GenerateMeta, "gen", "", "Generate metadata for update")
RootCmd.AddCommand(updateCmd)
updateCmd.PreRun = func(cmd *cobra.Command, args []string) {
if options.FullHelp {
cmd.Help()
os.Exit(0)
}
}
}

func runUpdate(cmd *cobra.Command, _ []string) error {
Expand Down
60 changes: 43 additions & 17 deletions cmd/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func RootUsage() {
h += QueueUsage()
h += ReportUsage()
h += UtilsUsage()

fmt.Println(h)
}

Expand All @@ -33,10 +32,14 @@ func ScanUsage() string {
## Start a general scan but exclude some of the module
osmedeus scan -t sample.com -x screenshot -x spider
## Initiate the scan using a speed option other than the default setting.
osmedeus scan -f vuln --tactic gently -t sample.com
osmedeus scan --threads-hold=10 -t sample.com
## Start a simple scan with other flow
osmedeus scan -f vuln -t sample.com
osmedeus scan -f extensive -t sample.com -t another.com
## Scan list of targets
osmedeus scan -T list_of_targets.txt
Expand All @@ -56,6 +59,9 @@ func ScanUsage() string {
## Start the scan with your custom workflow folder
osmedeus scan --wfFolder ~/custom-workflow/ -f your-custom-workflow -t sample.com
## Start a normal scan and backup entire workflow folder to the backup folder
osmedeus scan --backup -f domains -t list-of-subdomains.txt
## Start the scan with chunk inputs to review the output way more much faster
osmedeus scan --chunk --chunk-parts 20 -f cidr -t list-of-100-cidr.txt
Expand All @@ -78,7 +84,7 @@ func ScanUsage() string {
h += " osmedeus scan --tactic aggressive -f general -t sample.com\n"
h += " osmedeus scan -f extensive -t sample.com -t another.com\n"
h += " cat list_of_urls.txt | osmedeus scan -f urls\n"
h += " osmedeus scan --threads-hold=30 -f cidr -t 1.2.3.4/24\n"
h += " osmedeus scan --threads-hold=15 -f cidr -t 1.2.3.4/24\n"
h += " osmedeus scan -m ~/.osmedeus/core/workflow/test/dirbscan.yaml -t list_of_urls.txt\n"
h += " osmedeus scan --wfFolder ~/custom-workflow/ -f your-custom-workflow -t list_of_urls.txt\n"
h += " osmedeus scan --chunk --chunk-part 40 -c 2 -f cidr -t list-of-cidr.txt\n"
Expand Down Expand Up @@ -134,7 +140,7 @@ func QueueHelp(cmd *cobra.Command, _ []string) {
fmt.Println(cmd.UsageString())
h := QueueUsage()
fmt.Println(h)
printDocs()
printDocs(cmd)
}

func CloudUsage() string {
Expand Down Expand Up @@ -171,56 +177,76 @@ func ReportUsage() string {
// ScanHelp scan help message
func ScanHelp(cmd *cobra.Command, _ []string) {
fmt.Println(core.Banner())
fmt.Println(cmd.UsageString())
if options.FullHelp {
fmt.Println(cmd.UsageString())
}
h := ScanUsage()
fmt.Println(h)
printDocs()
printDocs(cmd)
}

// CloudHelp scan help message
func CloudHelp(cmd *cobra.Command, _ []string) {
fmt.Println(core.Banner())
fmt.Println(cmd.UsageString())
if options.FullHelp {
fmt.Println(cmd.UsageString())
}
h := CloudUsage()
fmt.Println(h)
printDocs()
printDocs(cmd)
}

// ConfigHelp config help message
func ConfigHelp(cmd *cobra.Command, _ []string) {
fmt.Println(core.Banner())
fmt.Println(cmd.UsageString())
if options.FullHelp {
fmt.Println(cmd.UsageString())
}
h := ConfigUsage()

fmt.Println(h)
printDocs()
printDocs(cmd)
}

// UtilsHelp utils help message
func UtilsHelp(cmd *cobra.Command, _ []string) {
fmt.Println(core.Banner())
fmt.Println(cmd.UsageString())
if options.FullHelp {
fmt.Println(cmd.UsageString())
}
h := UtilsUsage()
fmt.Println(h)
printDocs()
printDocs(cmd)
}

// ReportHelp utils help message
func ReportHelp(cmd *cobra.Command, _ []string) {
fmt.Println(core.Banner())
fmt.Println(cmd.UsageString())
if options.FullHelp {
fmt.Println(cmd.UsageString())
}
h := ReportUsage()
fmt.Println(h)
printDocs()
printDocs(cmd)
}

// RootHelp print help message
func RootHelp(cmd *cobra.Command, _ []string) {
fmt.Println(core.Banner())
fmt.Println(cmd.UsageString())
if options.FullHelp {
fmt.Println(cmd.UsageString())
}
RootUsage()
printDocs()
printDocs(cmd)
}

func printDocs() {
func printDocs(cmd *cobra.Command) {
if !options.FullHelp {
if cmd.Use == libs.BINARY {
fmt.Printf("💡 For full help message, please run: %s\n", color.GreenString("osmedeus --hh"))
} else {
fmt.Printf("💡 For full help message, please run: %s or %s\n", color.GreenString("osmedeus --hh"), color.GreenString("osmedeus "+cmd.Use+" --hh"))
}
}
fmt.Printf("📖 Documentation can be found here: %s\n", color.GreenString(libs.DOCS))
}
Loading

0 comments on commit c6bb0c4

Please sign in to comment.