Skip to content

Commit

Permalink
Server的一些命令,以及EXE的生成
Browse files Browse the repository at this point in the history
  • Loading branch information
s3cst4rs committed Mar 22, 2023
1 parent 8e5c8c5 commit 3c677f7
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/cli/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func validCATypes() []string {
return types
}

// 将CA从文件导入
var cmdImportCA = &cobra.Command{
Use: "import-ca",
Short: "Import certificate authority",
Expand Down Expand Up @@ -98,6 +99,7 @@ var cmdImportCA = &cobra.Command{
},
}

// CA证书写入文件
var cmdExportCA = &cobra.Command{
Use: "export-ca",
Short: "Export certificate authority",
Expand Down
1 change: 1 addition & 0 deletions server/cli/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/spf13/cobra"
)

// 启用守护进程,流程与rootCmd中的处理一致
var daemonCmd = &cobra.Command{
Use: "daemon",
Short: "Force start server in daemon mode",
Expand Down
1 change: 1 addition & 0 deletions server/cli/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/spf13/cobra"
)

// 将操作配置写入文件
var operatorCmd = &cobra.Command{
Use: "operator",
Short: "Generate operator configuration files",
Expand Down
1 change: 1 addition & 0 deletions server/cli/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/spf13/cobra"
)

// 解压assets文件
var unpackCmd = &cobra.Command{
Use: "unpack",
Short: "Unpack assets and exit",
Expand Down
2 changes: 2 additions & 0 deletions server/console/console-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ func newOperatorCmd(ctx *grumble.Context) {
}

// NewOperatorConfig - Generate a new player/client/operator configuration
// https://github.com/BishopFox/sliver/wiki/Multiplayer-Mode
// 猜测,连接TS是需要提前注册的
func NewOperatorConfig(operatorName string, lhost string, lport uint16) ([]byte, error) {
if !namePattern.MatchString(operatorName) {
return nil, errors.New("Invalid operator name (alphanumerics only)")
Expand Down
4 changes: 4 additions & 0 deletions server/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func Start(host string, port uint16) {
os.Exit(1)
}

// 阻止进程退出,并在退出时打印
// syscall.SIGTERM 结束程序(可以被捕获、阻塞或忽略)
// signal.Notify会在结束的时候向signals发送通知,signals将停止阻塞,向下执行,打印、关闭,并向done写入
// 外部的done收到消息,停止阻塞,Start函数执行结束
done := make(chan bool)
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM)
Expand Down
6 changes: 6 additions & 0 deletions server/generate/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ func SliverSharedLibrary(name string, otpSecret string, config *models.ImplantCo
}

// SliverExecutable - Generates a sliver executable binary
// 实时编译
// 就这???直接调用CMD进行编译
func SliverExecutable(name string, otpSecret string, config *models.ImplantConfig, save bool) (string, error) {
// Compile go code
appDir := assets.GetRootAppDir()
Expand Down Expand Up @@ -465,7 +467,9 @@ func SliverExecutable(name string, otpSecret string, config *models.ImplantConfi
}

// This function is a little too long, we should probably refactor it as some point
// 进行模板替换 准备工作
func renderSliverGoCode(name string, otpSecret string, config *models.ImplantConfig, goConfig *gogo.GoConfig) (string, error) {
// 校验GOOS、GOARCH是否支持
target := fmt.Sprintf("%s/%s", config.GOOS, config.GOARCH)
if _, ok := gogo.ValidCompilerTargets(*goConfig)[target]; !ok {
return "", fmt.Errorf("invalid compiler target: %s", target)
Expand All @@ -476,6 +480,7 @@ func renderSliverGoCode(name string, otpSecret string, config *models.ImplantCon

buildLog.Debugf("Generating new sliver binary '%s'", name)

// 构造项目路径
sliversDir := GetSliversDir() // ~/.sliver/slivers
projectGoPathDir := filepath.Join(sliversDir, config.GOOS, config.GOARCH, filepath.Base(name))
if _, err := os.Stat(projectGoPathDir); os.IsNotExist(err) {
Expand Down Expand Up @@ -546,6 +551,7 @@ func renderSliverGoCode(name string, otpSecret string, config *models.ImplantCon
// --------------
// Render Code
// --------------
// text/template :https://www.cnblogs.com/wanghui-garcia/p/10385062.html
sliverCodeTmpl := template.New("sliver")
sliverCodeTmpl, err = sliverCodeTmpl.Funcs(template.FuncMap{
"GenerateUserAgent": func() string {
Expand Down
2 changes: 2 additions & 0 deletions server/generate/implants.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func ImplantConfigSave(config *models.ImplantConfig) error {
}

// ImplantBuildSave - Saves a binary file into the database
// 保存文件
// 有储存MD5等值,定时在VT进行查询
func ImplantBuildSave(name string, config *models.ImplantConfig, fPath string) error {
rootAppDir, _ := filepath.Abs(assets.GetRootAppDir())
fPath, _ = filepath.Abs(fPath)
Expand Down
1 change: 1 addition & 0 deletions server/gogo/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func GoCmd(config GoConfig, cwd string, command []string) ([]byte, error) {
}

// GoBuild - Execute a go build command, returns stdout/error
// 处理参数并调用CMD编译
func GoBuild(config GoConfig, src string, dest string, buildmode string, tags []string, ldflags []string, gcflags, asmflags string, trimpath string) ([]byte, error) {
target := fmt.Sprintf("%s/%s", config.GOOS, config.GOARCH)
if _, ok := ValidCompilerTargets(config)[target]; !ok {
Expand Down

0 comments on commit 3c677f7

Please sign in to comment.