Skip to content

Commit

Permalink
updats
Browse files Browse the repository at this point in the history
  • Loading branch information
rangertaha committed Nov 7, 2024
1 parent 2d6a9be commit 7cb833d
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 11,605 deletions.
216 changes: 108 additions & 108 deletions cmd/urlinsane/typo/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,143 +14,143 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package typo

import (
"bytes"
"fmt"
"os"
"strings"
"text/template"
// import (
// "bytes"
// "fmt"
// "os"
// "strings"
// "text/template"

"github.com/jedib0t/go-pretty/v6/table"
"github.com/rangertaha/urlinsane/internal"
"github.com/rangertaha/urlinsane/internal/config"
// "github.com/jedib0t/go-pretty/v6/table"
// "github.com/rangertaha/urlinsane/internal"
// "github.com/rangertaha/urlinsane/internal/config"

_ "github.com/rangertaha/urlinsane/internal/plugins/information/all"
"github.com/rangertaha/urlinsane/internal/plugins/information/domains"
_ "github.com/rangertaha/urlinsane/internal/plugins/languages/all"
"github.com/rangertaha/urlinsane/internal/urlinsane"
"github.com/rangertaha/urlinsane/internal/utils"
"github.com/spf13/cobra"
)
// _ "github.com/rangertaha/urlinsane/internal/plugins/information/all"
// "github.com/rangertaha/urlinsane/internal/plugins/information/domains"
// _ "github.com/rangertaha/urlinsane/internal/plugins/languages/all"
// "github.com/rangertaha/urlinsane/internal/urlinsane"
// "github.com/rangertaha/urlinsane/internal/utils"
// "github.com/spf13/cobra"
// )

const domainHelpTemplate = `
// const domainHelpTemplate = `

ALGORITHMS:
Typosquatting algorithm plugins that generate typos.
// ALGORITHMS:
// Typosquatting algorithm plugins that generate typos.

{{.Algorithms}}
// {{.Algorithms}}


INFORMATION:
Information-gathering plugins that collect information on each domain
// INFORMATION:
// Information-gathering plugins that collect information on each domain

{{.Information}}
// {{.Information}}


LANGUAGES:
// LANGUAGES:

{{.Languages}}
// {{.Languages}}


KEYBOARDS:
// KEYBOARDS:

{{.Keyboards}}
// {{.Keyboards}}


EXAMPLE:
// EXAMPLE:

urlinsane typo domain google.com
urlinsane typo domain -a co google.com
urlinsane typo domain -t co,oi,oy -i ip,idna,ns google.com
urlinsane typo domain -l fr,en -k en1,en2 google.com
// urlinsane typo domain google.com
// urlinsane typo domain -a co google.com
// urlinsane typo domain -t co,oi,oy -i ip,idna,ns google.com
// urlinsane typo domain -l fr,en -k en1,en2 google.com

AUTHOR:
Rangertaha (rangertaha@gmail.com)
// AUTHOR:
// Rangertaha (rangertaha@gmail.com)

`
// `

type DomainHelpOptions struct {
Languages string
Keyboards string
Algorithms string
Information string
}
// type DomainHelpOptions struct {
// Languages string
// Keyboards string
// Algorithms string
// Information string
// }

var domainCliOptions bytes.Buffer
// var domainCliOptions bytes.Buffer

// rootCmd represents the typo command
var domainCmd = &cobra.Command{
Use: "domain [flags] [name]",
Short: "Detects domain typosquatting",
Long: `Detects domain typosquatting`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// if len(args) == 0 {
// cmd.Help()
// }
// // rootCmd represents the typo command
// var domainCmd = &cobra.Command{
// Use: "domain [flags] [name]",
// Short: "Detects domain typosquatting",
// Long: `Detects domain typosquatting`,
// Args: cobra.ExactArgs(1),
// Run: func(cmd *cobra.Command, args []string) {
// // if len(args) == 0 {
// // cmd.Help()
// // }

config, err := config.CobraConfig(cmd, args, internal.DOMAIN)
if err != nil {
fmt.Printf("%s", err)
os.Exit(0)
}
config.Type()
// config, err := config.CobraConfig(cmd, args, internal.DOMAIN)
// if err != nil {
// fmt.Printf("%s", err)
// os.Exit(0)
// }
// config.Type()

t := urlinsane.New(config)
t.Execute()
// t := urlinsane.New(config)
// t.Execute()

},
}
// },
// }

func init() {
TypoCmd.AddCommand(domainCmd)
domainHelpOptions := DomainHelpOptions{
LanguageTable(),
KeyboardTable(),
AlgorithmTable(),
DomainInformationTable(),
}
// func init() {
// TypoCmd.AddCommand(domainCmd)
// domainHelpOptions := DomainHelpOptions{
// LanguageTable(),
// KeyboardTable(),
// AlgorithmTable(),
// DomainInformationTable(),
// }

// Create a new template and parse into it.
tmpl := template.Must(template.New("help").Parse(domainHelpTemplate))
// // Create a new template and parse into it.
// tmpl := template.Must(template.New("help").Parse(domainHelpTemplate))

// Run the template to verify the output.
err := tmpl.Execute(&domainCliOptions, domainHelpOptions)
if err != nil {
fmt.Printf("Execution: %s", err)
}
// // Run the template to verify the output.
// err := tmpl.Execute(&domainCliOptions, domainHelpOptions)
// if err != nil {
// fmt.Printf("Execution: %s", err)
// }

domainCmd.SetUsageTemplate(templateBase + domainCliOptions.String())
domainCmd.CompletionOptions.DisableDefaultCmd = true
// domainCmd.SetUsageTemplate(templateBase + domainCliOptions.String())
// domainCmd.CompletionOptions.DisableDefaultCmd = true

// Plugins
domainCmd.Flags().StringP("info", "i", "all", "Information plugin IDs to apply")
// // Plugins
// domainCmd.Flags().StringP("info", "i", "all", "Information plugin IDs to apply")


// Filtering
domainCmd.Flags().Bool("all", false, "Scan all generated variants equivalent to: --ld 100")
domainCmd.Flags().Bool("show", false, "Show all generated variants")
domainCmd.Flags().Int("ld", 3, "Minimum levenshtein distance to scan")
domainCmd.Flags().String("filter", DomainInformationFields(), "Output filter options")

}

func DomainInformationTable() string {
t := table.NewWriter()
t.SetStyle(utils.StyleClear)
t.AppendHeader(table.Row{" ", "ID", "Description"})
for _, p := range domains.List() {
t.AppendRow([]interface{}{" ", p.Id(), p.Description()})
}
return t.Render()
}

func DomainInformationFields() (fields string) {
headers := []string{}
for _, i := range domains.List() {
for _, header := range i.Headers(){
headers = append(headers, strings.ToLower(header))
}
}
return strings.Join(headers, ",")
}
// // Filtering
// domainCmd.Flags().Bool("all", false, "Scan all generated variants equivalent to: --ld 100")
// domainCmd.Flags().Bool("show", false, "Show all generated variants")
// domainCmd.Flags().Int("ld", 3, "Minimum levenshtein distance to scan")
// domainCmd.Flags().String("filter", DomainInformationFields(), "Output filter options")

// }

// func DomainInformationTable() string {
// t := table.NewWriter()
// t.SetStyle(utils.StyleClear)
// t.AppendHeader(table.Row{" ", "ID", "Description"})
// for _, p := range domains.List() {
// t.AppendRow([]interface{}{" ", p.Id(), p.Description()})
// }
// return t.Render()
// }

// func DomainInformationFields() (fields string) {
// headers := []string{}
// for _, i := range domains.List() {
// for _, header := range i.Headers(){
// headers = append(headers, strings.ToLower(header))
// }
// }
// return strings.Join(headers, ",")
// }
Loading

0 comments on commit 7cb833d

Please sign in to comment.