Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
✏️ Documentation started!
Browse files Browse the repository at this point in the history
  • Loading branch information
CosasDePuma committed May 21, 2020
1 parent 8029d50 commit 076f648
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 110 deletions.
10 changes: 5 additions & 5 deletions app/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
)

const (
// LOGINFO TODO: Doc
// LOGINFO displays no colored messages
LOGINFO = iota
// LOGERROR TODO Doc
// LOGERROR displays highlighted error messages
LOGERROR
)

// App TODO: Doc
// App contains all the information related to the application displayed on the screen
type App struct {
gui *gocui.Gui
lock *sync.Mutex
Expand All @@ -37,7 +37,7 @@ type App struct {
}
}

// NewApp TODO: Doc
// NewApp generates a new user interface
func NewApp() (*App, error) {
gui, err := gocui.NewGui(gocui.OutputNormal, false)
if err != nil {
Expand Down Expand Up @@ -66,7 +66,7 @@ func NewApp() (*App, error) {
}, nil
}

// Run TODO: Doc
// Run allows to start the application
func (app *App) Run() error {
defer logrus.Debug("Application closed")
// Configuration
Expand Down
7 changes: 1 addition & 6 deletions app/elliot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/cosasdepuma/elliot/app/cli"
)

// Entrypoint TODO: Doc
// Entrypoint defines the starting point of the program
func Entrypoint() {
logrus.SetLevel(logrus.InfoLevel)
logs, err := os.OpenFile("elliot.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
Expand All @@ -30,8 +30,3 @@ func Entrypoint() {
fmt.Printf("[!] %s\n", err.Error())
}
}

/*
Documentation:
- Subdomains: A lot of APIs (https://github.com/tomnomnom/assetfinder)
*/
4 changes: 2 additions & 2 deletions app/env/env.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package env

// Config TODO: Doc
// Config serves as a proxy to transfer information to the plugins
var Config = struct {
Target string
Params interface{}
}{}

// Channels TODO: Doc
// Channels collects the most important communication channels between the goroutines and the main thread
var Channels struct {
Ok chan string
Bad chan error
Expand Down
4 changes: 3 additions & 1 deletion app/plugins/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/cosasdepuma/elliot/app/plugins/subdomain"
)

// Plugins TODO: Doc
var (
// Plugins collects all available plugins that can be run
Plugins = map[string]interface {
Check() error
Run()
Expand All @@ -16,8 +16,10 @@ var (
"robots.txt": robots.Plugin{},
"subdomain": subdomain.Plugin{},
}
// Required specifies what parameters are necessary to run a plugin
Required = map[string]string{
"portscanner": "Ports",
}
// Amount specifies how many plugins are available
Amount = len(Plugins)
)
19 changes: 9 additions & 10 deletions app/plugins/portscanner/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,38 @@ import (
"strings"
)

// Port TODO: Doc
type Port struct {
type sPort struct {
protocol string
number int
status string
service string
banner string
}

func newPort(protocol string, number int) *Port {
port := Port{protocol: protocol, number: number, status: "close", service: "unknown"}
func newPort(protocol string, number int) *sPort {
port := sPort{protocol: protocol, number: number, status: "close", service: "unknown"}
port.predictService()
return &port
}

func (port *Port) setBanner(banner string) {
func (port *sPort) setBanner(banner string) {
port.banner = banner
}

func (port *Port) setOpen() {
func (port *sPort) setOpen() {
port.status = "open"
}

// IsOpen TODO: Doc
func (port Port) IsOpen() bool {
// IsOpen
func (port sPort) isOpen() bool {
return port.status == "open"
}

func (port Port) String() string {
func (port sPort) string() string {
return fmt.Sprintf("%5d/%s\t%-7s\t%-9s\t%s", port.number, port.protocol, port.status, port.service, strings.TrimSpace(port.banner))
}

func (port *Port) predictService() {
func (port *sPort) predictService() {
if port.protocol == "tcp" {
if predict, ok := mTCP[port.number]; ok {
port.service = predict
Expand Down
16 changes: 8 additions & 8 deletions app/plugins/portscanner/portscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/cosasdepuma/elliot/app/validator"
)

// Plugin TODO: Doc
// Plugin allows it to be executed by Elliot
type Plugin struct{}

// Check TODO: Doc
// Check that all parameters are defined correctly
func (plugin Plugin) Check() error {
if !validator.IsValidDomain(env.Config.Target) {
return errors.New("A valid domain should be specified")
Expand All @@ -29,28 +29,28 @@ func (plugin Plugin) Check() error {
return nil
}

// Run TODO: Doc
// Run is the entrypoint of the plugin
func (plugin Plugin) Run() {
if err := plugin.Check(); err != nil {
env.Channels.Bad <- err
return
}

results := map[int]string{}
channel := make(chan *Port, len(env.Config.Params.([]int)))
channel := make(chan *sPort, len(env.Config.Params.([]int)))

scanner := NewPortScanner(env.Config.Target)
scanner := newPortScanner(env.Config.Target)

for _, port := range env.Config.Params.([]int) {
go func(port int) { channel <- scanner.CheckTCPPort(port) }(port)
go func(port int) { channel <- scanner.checkTCPPort(port) }(port)
}

progress := len(env.Config.Params.([]int))
for progress > 0 {
progress--
result := <-channel
if result.IsOpen() {
results[result.number] = result.String()
if result.isOpen() {
results[result.number] = result.string()
}
}

Expand Down
20 changes: 8 additions & 12 deletions app/plugins/portscanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,30 @@ import (
"time"
)

// PortScanner TODO: Doc
type PortScanner struct {
type sPortScanner struct {
host string
lock sync.Mutex
pool chan bool
timeout time.Duration
Results map[int]*Port
Results map[int]*sPort
}

// NewPortScanner TODO: Doc
func NewPortScanner(host string) *PortScanner {
return &PortScanner{
func newPortScanner(host string) *sPortScanner {
return &sPortScanner{
host: host,
timeout: time.Second * time.Duration(2),
lock: sync.Mutex{}, Results: map[int]*Port{}}
lock: sync.Mutex{}, Results: map[int]*sPort{}}
}

// SetTimeout TODO: Doc
func (scanner *PortScanner) SetTimeout(timeout time.Duration) {
func (scanner *sPortScanner) setTimeout(timeout time.Duration) {
scanner.timeout = timeout
}

func (scanner *PortScanner) withPort(port int) string {
func (scanner *sPortScanner) withPort(port int) string {
return fmt.Sprintf("%s:%d", scanner.host, port)
}

// CheckTCPPort TODO: Doc
func (scanner *PortScanner) CheckTCPPort(port int) *Port {
func (scanner *sPortScanner) checkTCPPort(port int) *sPort {
scannedPort := newPort("tcp", port)

addr, err := net.ResolveTCPAddr("tcp4", scanner.withPort(port))
Expand Down
41 changes: 3 additions & 38 deletions app/plugins/robots/robots.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/cosasdepuma/elliot/app/validator"
)

// Plugin TODO: Doc
// Plugin allows it to be executed by Elliot
type Plugin struct{}

// Check TODO: Doc
// Check that all parameters are defined correctly
func (plgn Plugin) Check() error {
if !validator.IsValidURL(env.Config.Target) {
return errors.New("A valid URL should be specified")
Expand All @@ -23,7 +23,7 @@ func (plgn Plugin) Check() error {
return nil
}

// Run TODO: Doc
// Run is the entrypoint of the plugin
func (plgn Plugin) Run() {
if err := plgn.Check(); err != nil {
env.Channels.Bad <- err
Expand All @@ -43,41 +43,6 @@ func (plgn Plugin) Run() {
env.Channels.Bad <- errors.New("Cannot read robots.txt")
return
}

// results := strings.Split(strings.TrimSpace(string(bRobots)), "\n")

// TODO: Implement disallow only
// results = filterDisallow(results)

// TODO: Implement extended
// results = extendedMode(results)

results := strings.TrimSpace(string(bRobots))
env.Channels.Ok <- results
}

func filterDisallow(robots []string) []string {
disallowed := make([]string, 0)
for _, robot := range robots {
if strings.HasPrefix(robot, "Disallow: ") {
disallowed = append(disallowed, strings.TrimSpace(strings.SplitN(robot, ": ", 2)[1]))
}
}
return disallowed
}

func extendedMode(robots []string) []string {
extended := make([]string, 0)
for _, robot := range robots {
if strings.HasPrefix(robot, "Allow: ") || strings.HasPrefix(robot, "Disallow: ") || strings.HasPrefix(robot, "/") {
splits := strings.SplitN(robot, "/", 2)
url := env.Config.Target
if !strings.HasSuffix(url, "/") {
url = fmt.Sprintf("%s%s", url, "/")
}
robot = fmt.Sprintf("%s%s%s", splits[0], url, splits[1])
}
extended = append(extended, robot)
}
return extended
}
12 changes: 8 additions & 4 deletions app/plugins/subdomain/subdomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/cosasdepuma/elliot/app/validator"
)

// Plugin TODO: Doc
// Plugin allows it to be executed by Elliot
type Plugin struct{}

type function func(string) ([]string, error)

// Check TODO: Doc
// Check that all parameters are defined correctly
func (plgn Plugin) Check() error {
if !validator.IsValidDomain(env.Config.Target) {
return errors.New("A valid domain should be specified")
Expand All @@ -23,8 +23,7 @@ func (plgn Plugin) Check() error {
return nil
}

// Run TODO: Doc
// -- Fixme: Can't rerun module
// Run is the entrypoint of the plugin
func (plgn Plugin) Run() {
if err := plgn.Check(); err != nil {
env.Channels.Bad <- err
Expand Down Expand Up @@ -87,3 +86,8 @@ func filterDuplicates(data []string) []string {
}
return subdomains
}

/*
Documentation:
- Subdomains: A lot of APIs (https://github.com/tomnomnom/assetfinder)
*/
3 changes: 1 addition & 2 deletions app/plugins/subdomain/threatcrowd.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package subdomain

import (
"errors"

"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand Down
Loading

0 comments on commit 076f648

Please sign in to comment.