/
hashcat.go
74 lines (60 loc) · 2.07 KB
/
hashcat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package controllers
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/lachlan2k/phatcrack/api/internal/hashcathelpers"
"github.com/lachlan2k/phatcrack/api/internal/resources"
"github.com/lachlan2k/phatcrack/api/internal/util"
"github.com/lachlan2k/phatcrack/common/pkg/apitypes"
)
func HookHashcatEndpoints(api *echo.Group) {
api.GET("/ping", func(c echo.Context) error {
return c.String(http.StatusOK, "pong")
})
api.GET("/hashtypes", func(c echo.Context) error {
return c.JSON(http.StatusOK, apitypes.HashTypesDTO{
HashTypes: resources.GetHashTypeMap(),
})
})
api.POST("/detect-hashtype", func(c echo.Context) error {
req, err := util.BindAndValidate[apitypes.DetectHashTypeRequestDTO](c)
if err != nil {
return err
}
possibleTypes, err := hashcathelpers.IdentifyHashTypes(req.TestHash, req.HasUsername)
if err != nil {
return util.ServerError("Failed to find hash candidates", err)
}
return c.JSON(http.StatusOK, apitypes.DetectHashTypeResponseDTO{
PossibleTypes: possibleTypes,
})
})
api.POST("/verify-hashes", func(c echo.Context) error {
req, err := util.BindAndValidate[apitypes.VerifyHashesRequestDTO](c)
if err != nil {
return err
}
// TODO: Do more investigation as to what happens when hashcat rejects hashes
normalized, err := hashcathelpers.NormalizeHashes(req.Hashes, req.HashType, req.HasUsernames)
isValid := len(normalized) > 0 && err != nil
return c.JSON(http.StatusOK, apitypes.VerifyHashesResponseDTO{
Valid: isValid,
})
})
api.POST("/normalize-hashes", func(c echo.Context) error {
req, err := util.BindAndValidate[apitypes.NormalizeHashesRequestDTO](c)
if err != nil {
return err
}
// TODO: Do more investigation as to what happens when hashcat rejects hashes
normalized, err := hashcathelpers.NormalizeHashes(req.Hashes, req.HashType, req.HasUsernames)
isValid := len(normalized) > 0 && err != nil
if !isValid {
normalized = []string{}
}
return c.JSON(http.StatusOK, apitypes.NormalizeHashesResponseDTO{
Valid: isValid,
NormalizedHashes: normalized,
})
})
}