Skip to content

Commit aaffbaf

Browse files
committed
参考nuclie实现self更新
1 parent b230672 commit aaffbaf

File tree

9 files changed

+201
-7
lines changed

9 files changed

+201
-7
lines changed

cmd/commons/core/banner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const banner = `
1414
1515
`
1616

17+
// TODO 修改版本号
18+
const version = "0.0.9"
19+
1720
func ShowBanner(Version string) {
1821
log.Println(banner)
1922
log.Println("\t\t\tAuthor: SummerSec Version:", Version+" Github: https://Github.com/SummerSec\n")

cmd/commons/core/options.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type Options struct {
4646
Shell bool
4747
// 强制开启HTTP 1.1
4848
H1 bool
49+
// 更新到最新版本
50+
Update bool
4951
}
5052

5153
func (o Options) toString() interface{} {
@@ -72,12 +74,13 @@ func ParseOptions() *Options {
7274
flag.StringVar(&options.IP, "i", "", "ip segment example: -i=192.168.1.1/32")
7375
flag.BoolVar(&options.Shell, "shell", false, "whether to enter the interactive shell")
7476
flag.BoolVar(&options.H1, "h1", false, "force to use HTTP 1.1")
77+
flag.BoolVar(&options.Update, "update", false, "update to the latest version")
7578
flag.Parse()
7679

7780
// TODO 修改版本号
78-
v := "0.0.9"
79-
80-
ShowBanner(v)
81+
ShowBanner(version)
82+
logs.SaveLogs(options.LogFile)
83+
showVerbose(options)
8184

8285
if options.Version {
8386
//ShowBanner(v)
@@ -97,8 +100,6 @@ func ParseOptions() *Options {
97100
//ShowBanner(v)
98101
flag.PrintDefaults()
99102
}
100-
showVerbose(options)
101-
logs.SaveLogs(options.LogFile)
102103

103104
return options
104105

cmd/commons/core/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func (r *Runner) Run() {
4040
urls, _ = utils.ReadFile(r.options.File)
4141
} else if r.options.IP != "" {
4242
urls = utils.GetIPToUrlsLinks(r.options.IP, urls)
43+
} else if r.options.Update {
44+
selfUpdate()
4345
} else {
4446
log.Error("No file or url or ips specified")
4547
return

cmd/commons/core/update.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package core
2+
3+
import (
4+
log "github.com/sirupsen/logrus"
5+
"github.com/tj/go-update"
6+
"github.com/tj/go-update/progress"
7+
githubUpdateStore "github.com/tj/go-update/stores/github"
8+
"runtime"
9+
)
10+
11+
const (
12+
Owner = "SummerSec"
13+
Repo = "SpringExploit"
14+
)
15+
16+
func selfUpdate() {
17+
var command string
18+
switch runtime.GOOS {
19+
case "windows":
20+
command = "nuclei.exe"
21+
default:
22+
command = "nuclei"
23+
}
24+
m := &update.Manager{
25+
Command: command,
26+
Store: &githubUpdateStore.Store{
27+
Owner: Owner,
28+
Repo: Repo,
29+
Version: version,
30+
},
31+
}
32+
33+
releases, err := m.LatestReleases()
34+
if err != nil {
35+
log.Error("Failed to get releases", err)
36+
return
37+
}
38+
if len(releases) == 0 {
39+
log.Info("No updates available")
40+
return
41+
}
42+
latest := releases[0]
43+
var currentOS string
44+
switch runtime.GOOS {
45+
case "darwin":
46+
currentOS = "macOS"
47+
default:
48+
currentOS = runtime.GOOS
49+
}
50+
final := latest.FindZip(currentOS, runtime.GOARCH)
51+
if final == nil {
52+
log.Error("No update available for", currentOS, "and", runtime.GOARCH)
53+
}
54+
tarball, err := final.DownloadProxy(progress.Reader)
55+
if err != nil {
56+
log.Error("could not install latest release ", err)
57+
return
58+
}
59+
if err := m.Install(tarball); err != nil {
60+
log.Error("could not install latest release", err)
61+
return
62+
}
63+
64+
log.Infof("Successfully Updated to %s Version %s", Repo, latest.Version)
65+
66+
}

cmd/commons/core/update_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package core
2+
3+
import "testing"
4+
5+
func Test_selfUpdate(t *testing.T) {
6+
tests := []struct {
7+
name string
8+
}{
9+
// TODO: Add test cases.
10+
}
11+
for _, tt := range tests {
12+
t.Run(tt.name, func(t *testing.T) {
13+
selfUpdate()
14+
})
15+
}
16+
}

cmd/commons/utils/os.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package utils
2+
3+
import "runtime"
4+
5+
// GetOSInfo 获取当前运行的操作系统信息
6+
func GetOSInfo() string {
7+
// 获取操作系统信息
8+
return runtime.GOOS + "_" + runtime.GOARCH
9+
}

cmd/test/emun.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
package main
22

3-
import "github.com/SummerSec/SpringExploit/cmd/commons/attack"
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"github.com/imroc/req/v3"
7+
"runtime"
8+
)
49

510
func main() {
6-
attack.CVE202222963()
11+
u := "https://api.github.com/repos/SummerSec/SpringExploit/releases/latest"
12+
fmt.Println(u)
13+
resp, _ := req.R().Get(u)
14+
body, _ := resp.ToString()
15+
// body to map
16+
fmt.Println(body)
17+
var m map[string]interface{}
18+
json.Unmarshal([]byte(body), &m)
19+
// get release tag
20+
tag := m["tag_name"]
21+
22+
fmt.Println(tag)
23+
fmt.Println(runtime.GOOS + "_" + runtime.GOARCH)
724

825
}

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ require (
1313
)
1414

1515
require (
16+
github.com/apex/log v1.9.0 // indirect
1617
github.com/c-bata/go-prompt v0.2.6 // indirect
18+
github.com/c4milo/unpackit v0.1.0 // indirect
19+
github.com/google/go-github v17.0.0+incompatible // indirect
20+
github.com/google/go-querystring v1.1.0 // indirect
21+
github.com/gosuri/uilive v0.0.4 // indirect
22+
github.com/gosuri/uiprogress v0.0.1 // indirect
1723
github.com/hashicorp/errwrap v1.0.0 // indirect
1824
github.com/hashicorp/go-multierror v1.1.1 // indirect
1925
github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e // indirect
26+
github.com/tj/go-update v2.2.5-0.20200519121640-62b4b798fd68+incompatible
2027
golang.org/x/net v0.0.0-20220111093109-d55c255bac03 // indirect
2128
golang.org/x/text v0.3.7 // indirect
2229
)

0 commit comments

Comments
 (0)