-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use seclist for discoverable endpoints
- Loading branch information
1 parent
88b782d
commit 6d89704
Showing
10 changed files
with
290 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package seclist | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"io" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
type SecList struct { | ||
Name string | ||
Items []string | ||
} | ||
|
||
func NewSecList(name string) *SecList { | ||
return &SecList{ | ||
Name: name, | ||
Items: []string{}, | ||
} | ||
} | ||
|
||
func NewSecListFromFile(name, filepath string) (*SecList, error) { | ||
s := NewSecList(name) | ||
err := s.ImportFromFile(filepath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s, nil | ||
} | ||
|
||
func NewSecListFromURL(name, url string) (*SecList, error) { | ||
s := NewSecList(name) | ||
err := s.DownloadFromURL(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s, nil | ||
} | ||
|
||
func (s *SecList) ImportFromFile(filepath string) error { | ||
file, err := os.Open(filepath) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
s.Items = append(s.Items, line) | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *SecList) DownloadFromURL(url string) error { | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return errors.New("sec list download failed") | ||
} | ||
|
||
tempFile, err := os.CreateTemp("", "seclist") | ||
if err != nil { | ||
return err | ||
} | ||
defer tempFile.Close() | ||
|
||
_, err = io.Copy(tempFile, resp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
filepath := tempFile.Name() | ||
err = s.ImportFromFile(filepath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = os.Remove(filepath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.