Skip to content

Commit

Permalink
Remove Makefile + Display all sherlock tasks and submit task arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
qu35t-code committed Nov 12, 2023
1 parent 914f696 commit 343422d
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 70 deletions.
29 changes: 0 additions & 29 deletions Makefile

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Another optional argument is `--download` or `-d`, which allows you to download
![Sherlock_2](./assets/sherlocks_2.gif)
To submit the answers for each task, you can add the `-t` / `--task` flag followed by the task number.
![Sherlock_3](./assets/sherlocks_3.gif)
### info
The `info` command will retrieve information from the active machine (if any) and display it. If no argument is supplied, the logged-in user's information will be displayed.
Expand Down
Binary file modified assets/sherlocks_2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sherlocks_3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 21 additions & 9 deletions cmd/sherlocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

var sherlockNameParam string
var sherlockDownloadPath string
var sherlockTaskID int

const (
sherlocksURL = baseAPIURL + "/sherlocks?state=active"
Expand Down Expand Up @@ -112,24 +113,34 @@ var sherlocksCmd = &cobra.Command{
}
log.Println("SherlockID :", sherlockID)

if sherlockTaskID != 0 {
err := utils.GetSherlockTaskByID(proxyParam, sherlockID, sherlockTaskID)
if err != nil {
fmt.Println(err)
return
}
return
}

err = utils.GetSherlockGeneralInformations(proxyParam, sherlockID, sherlockDownloadPath)

if err != nil {
fmt.Println(err)
return
}
ret := false

for !ret {
ret, err = utils.GetSherlockTasks(proxyParam, sherlockID)
if err != nil {
fmt.Println(err)
return
data, err := utils.GetSherlockTasks(proxyParam, sherlockID)
if err != nil {
fmt.Println(err)
return
}
for _, task := range data.Tasks {
if task.Completed {
fmt.Printf("\n%s (DONE) :\n%s\n\n", task.Title, task.Description)
} else {
fmt.Printf("\n%s :\n%s\n\n", task.Title, task.Description)
}
}

fmt.Println("\nNo tasks left")

return
}
app := tview.NewApplication()
Expand Down Expand Up @@ -183,4 +194,5 @@ func init() {
rootCmd.AddCommand(sherlocksCmd)
sherlocksCmd.Flags().StringVarP(&sherlockNameParam, "sherlock_name", "s", "", "Sherlock Name")
sherlocksCmd.Flags().StringVarP(&sherlockDownloadPath, "download", "d", "", "Download Sherlock Resources")
sherlocksCmd.Flags().IntVarP(&sherlockTaskID, "task", "t", 0, "Task ID")
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/rivo/tview v0.0.0-20230928053139-9bc1d28d88a9
github.com/sahilm/fuzzy v0.1.0
github.com/spf13/cobra v1.5.0
golang.org/x/term v0.5.0
golang.org/x/term v0.6.0
)

require (
Expand All @@ -20,7 +20,7 @@ require (
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/rivo/uniseg v0.4.4 // indirect
Expand Down
8 changes: 5 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxec
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
Expand Down Expand Up @@ -74,12 +74,14 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
Expand Down
70 changes: 43 additions & 27 deletions utils/sherlocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ type SherlockNameID struct {
}

func getSherlockDownloadLink(proxyURL string, sherlockID string) (string, error) {
url := "https://www.hackthebox.com/api/v4/sherlocks/" + sherlockID + "/download_link"
// url := "https://www.hackthebox.com/api/v4/sherlocks/" + sherlockID + "/download_link"

// url := "https://www.hackthebox.com/api/v4/challenge/download/196"
url := "https://www.hackthebox.com/api/v4/challenge/download/196"

// return url, nil
return url, nil

resp, err := HtbRequest(http.MethodGet, url, proxyURL, nil)

Check failure on line 49 in utils/sherlocks.go

View workflow job for this annotation

GitHub Actions / lint

unreachable: unreachable code (govet)

Check failure on line 49 in utils/sherlocks.go

View workflow job for this annotation

GitHub Actions / lint

unreachable: unreachable code (govet)
if err != nil {
Expand Down Expand Up @@ -113,7 +113,7 @@ func submitTask(proxyURL string, sherlockID string, taskID string, flag string)
return message, nil
}

func GetSherlockTasks(proxyURL string, sherlockID string) (bool, error) {
func GetSherlockTaskByID(proxyURL string, sherlockID string, sherlockTaskID int) error {
url := "https://www.hackthebox.com/api/v4/sherlocks/" + sherlockID + "/tasks"
resp, err := HtbRequest(http.MethodGet, url, proxyURL, nil)
if err != nil {
Expand All @@ -123,37 +123,53 @@ func GetSherlockTasks(proxyURL string, sherlockID string) (bool, error) {

jsonData, _ := io.ReadAll(resp.Body)

var parsedData SherlockDataTasks
err = json.Unmarshal([]byte(jsonData), &parsedData)
var sherlockData SherlockDataTasks
err = json.Unmarshal([]byte(jsonData), &sherlockData)
if err != nil {
return true, fmt.Errorf("error parsing JSON: %w", err)
return fmt.Errorf("error parsing JSON: %w", err)
}

for _, task := range parsedData.Tasks {
if !task.Completed {
fmt.Printf("\n%s :\n%s\n\n", task.Title, task.Description)
fmt.Print("Flag : ")
taskID := strconv.Itoa(task.ID)
flagByte, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Println("Error reading flag")
// return "", fmt.Errorf("error reading flag")
}
flag := string(flagByte)
log.Println(flag)
if sherlockTaskID >= 1 && sherlockTaskID <= len(sherlockData.Tasks) {
fmt.Printf("\n%s :\n%s\n\n", sherlockData.Tasks[sherlockTaskID-1].Title, sherlockData.Tasks[sherlockTaskID-1].Description)
fmt.Print("Flag : ")
taskID := strconv.Itoa(sherlockData.Tasks[sherlockTaskID-1].ID)
flagByte, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Println("Error reading flag")
}
flag := string(flagByte)
log.Println(flag)

message, err := submitTask(proxyURL, sherlockID, taskID, flag)
message, err := submitTask(proxyURL, sherlockID, taskID, flag)

if err != nil {
return true, err
}
if err != nil {
return err
}

fmt.Println(message)
fmt.Println(message)
} else {
fmt.Println("Invalid task ID :", sherlockTaskID)
}
return nil
}

return false, nil
}
func GetSherlockTasks(proxyURL string, sherlockID string) (*SherlockDataTasks, error) {
url := "https://www.hackthebox.com/api/v4/sherlocks/" + sherlockID + "/tasks"
resp, err := HtbRequest(http.MethodGet, url, proxyURL, nil)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()

jsonData, _ := io.ReadAll(resp.Body)

var parsedData SherlockDataTasks
err = json.Unmarshal([]byte(jsonData), &parsedData)
if err != nil {
return nil, fmt.Errorf("error parsing JSON: %w", err)
}
return true, nil

return &parsedData, nil
}

func GetSherlockGeneralInformations(proxyURL string, sherlockID string, sherlockDownloadPath string) error {
Expand Down
22 changes: 22 additions & 0 deletions utils/vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ import (
"time"
)

func DownloadVPN(proxyURL string) error {
url := "https://www.hackthebox.com/api/v4/connections/servers?product=labs"
// url := "https://www.hackthebox.com/api/v4/connections/servers?product=starting_point"
// url := "https://www.hackthebox.com/api/v4/connections/servers?product=endgames"
// url := "https://www.hackthebox.com/api/v4/connections/servers?product=fortresses"
// url := "https://www.hackthebox.com/api/v4/connections/servers?product=competitive"

// {"status":true,"data":{"disabled":false,"assigned":{"id":18,"friendly_name":"EU VIP 7","current_clients":8,"location":"EU","location_type_friendly":"EU - VIP"},"options":{"EU":{"EU - Free"
resp, err := HtbRequest(http.MethodGet, url, proxyURL, nil)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
fmt.Println("error:", resp.StatusCode)
return nil
}

return nil
}

func StartVPN(configPath string) string {
fmt.Println("VPN is starting...")
pidFile := baseDirectory + "/lab-vpn.pid"
Expand Down

0 comments on commit 343422d

Please sign in to comment.