Skip to content

Commit

Permalink
add afrog version check
Browse files Browse the repository at this point in the history
  • Loading branch information
zan8in committed Apr 26, 2022
1 parent 269b236 commit 27c1423
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
18 changes: 11 additions & 7 deletions cmd/afrog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/zan8in/afrog/pkg/utils"
"os"

"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -33,16 +34,15 @@ func main() {
}

app.Action = func(c *cli.Context) error {

title := log.LogColor.Vulner(runner.ShowBanner() + " - V" + config.Version)

upgrade := upgrade.New()
upgrade.UpgradeAfrogPocs()

showBanner(upgrade.LastestAfrogVersion)

defconfig := log.LogColor.Low("Default Conf " + options.Config.GetConfigPath())
defpocdir := log.LogColor.Low("Default Pocs " + poc.GetPocPath())

fmt.Println(title + "\r\n" + defconfig + "\r\n" + defpocdir + " v" + upgrade.LastestVersion + "")
fmt.Println(defconfig + "\r\n" + defpocdir + " v" + upgrade.LastestVersion + "")

htemplate.Filename = options.Output
if err := htemplate.New(); err != nil {
Expand Down Expand Up @@ -85,8 +85,12 @@ func main() {
}
}

func PrintTraceInfo(result *core.Result) {
for i, v := range result.AllPocResult {
log.Log().Info(fmt.Sprintf("\r\n%s(%d)\r\n%s\r\n\r\n%s(%d)\r\n%s\r\n", "Request:", i, v.ReadFullResultRequestInfo(), "Response:", i, v.ReadFullResultResponseInfo()))
func showBanner(afrogLatestversion string) {
title := log.LogColor.Vulner(runner.ShowBanner() + " - V" + config.Version)
old := ""
if utils.Compare(afrogLatestversion, ">", config.Version) {
old = log.LogColor.Critical(" (outdated)")
old += log.LogColor.Title(" --> https://github.com/zan8in/afrog/releases/tag/v" + afrogLatestversion)
}
fmt.Println(title + old)
}
26 changes: 22 additions & 4 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ import (
)

type Upgrade struct {
HomeDir string
CurrVersion string
RemoteVersion string
LastestVersion string
HomeDir string
CurrVersion string
RemoteVersion string
LastestVersion string
LastestAfrogVersion string
}

const (
upHost = "http://binbin.run/afrog-release"
upPathName = "/afrog-pocs"
upPath = "/afrog-pocs.zip"
upRemoteVersion = "/version"
afrogVersion = "/afrog.version"
)

func New() *Upgrade {
Expand Down Expand Up @@ -53,9 +55,25 @@ func (u *Upgrade) CheckUpgrade() (bool, error) {
u.CurrVersion = curVersion
u.RemoteVersion = strings.TrimSpace(string(remoteVersion))

u.LastestAfrogVersion, _ = getAfrogVersion()

return utils.Compare(strings.TrimSpace(string(remoteVersion)), ">", curVersion), nil
}

func getAfrogVersion() (string, error) {
resp, err := http.Get(upHost + afrogVersion)
if err != nil {
return "", errors.New("failed to get remote version number")
}
defer resp.Body.Close()

afrogversion, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.New("failed to get remote version number")
}
return strings.TrimSpace(string(afrogversion)), nil
}

func (u *Upgrade) UpgradeAfrogPocs() {
isUp, err := u.CheckUpgrade()
if err != nil {
Expand Down

0 comments on commit 27c1423

Please sign in to comment.