Skip to content

Commit

Permalink
Merge branch 'master' into v0.5.0
Browse files Browse the repository at this point in the history
* master:
  fix: change ControlPath to .vuls of SSH option (#618)
  feat: Add -vvv option to scan cmd (#617)
  fix: SSH session multiplexing (#616)
  • Loading branch information
kotakanbe committed Mar 15, 2018
2 parents 5b4a298 + 0c919da commit 5e1a24e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 25 deletions.
43 changes: 25 additions & 18 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Expand Up @@ -111,3 +111,7 @@
[[constraint]]
branch = "master"
name = "golang.org/x/crypto"

[[constraint]]
branch = "master"
name = "github.com/mitchellh/go-homedir"
10 changes: 10 additions & 0 deletions commands/configtest.go
Expand Up @@ -45,6 +45,7 @@ type ConfigtestCmd struct {
deep bool

debug bool
vvv bool
}

// Name return subcommand name
Expand All @@ -68,6 +69,7 @@ func (*ConfigtestCmd) Usage() string {
[-containers-only]
[-http-proxy=http://192.168.0.1:8080]
[-debug]
[-vvv]
[SERVER]...
`
Expand Down Expand Up @@ -125,6 +127,8 @@ func (p *ConfigtestCmd) SetFlags(f *flag.FlagSet) {
"containers-only",
false,
"Test containers only. Default: Test both of hosts and containers")

f.BoolVar(&p.vvv, "vvv", false, "ssh -vvv")
}

// Execute execute
Expand All @@ -134,6 +138,11 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa
c.Conf.LogDir = p.logDir
util.Log = util.NewCustomLogger(c.ServerInfo{})

if err := mkdirDotVuls(); err != nil {
util.Log.Errorf("Failed to create .vuls: %s", err)
return subcommands.ExitUsageError
}

var keyPass string
var err error
if p.askKeyPassword {
Expand Down Expand Up @@ -161,6 +170,7 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa
if !(c.Conf.Fast || c.Conf.Offline || c.Conf.Deep) {
c.Conf.Fast = true
}
c.Conf.Vvv = p.vvv

var servernames []string
if 0 < len(f.Args()) {
Expand Down
10 changes: 10 additions & 0 deletions commands/scan.go
Expand Up @@ -49,6 +49,7 @@ type ScanCmd struct {
skipBroken bool
sshNative bool
pipe bool
vvv bool
timeoutSec int
scanTimeoutSec int
}
Expand Down Expand Up @@ -79,6 +80,7 @@ func (*ScanCmd) Usage() string {
[-timeout-scan=7200]
[-debug]
[-pipe]
[-vvv]
[SERVER]...
`
Expand Down Expand Up @@ -162,6 +164,8 @@ func (p *ScanCmd) SetFlags(f *flag.FlagSet) {
false,
"Use stdin via PIPE")

f.BoolVar(&p.vvv, "vvv", false, "ssh -vvv")

f.IntVar(
&p.timeoutSec,
"timeout",
Expand All @@ -184,6 +188,11 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
c.Conf.LogDir = p.logDir
util.Log = util.NewCustomLogger(c.ServerInfo{})

if err := mkdirDotVuls(); err != nil {
util.Log.Errorf("Failed to create .vuls: %s", err)
return subcommands.ExitUsageError
}

var keyPass string
var err error
if p.askKeyPassword {
Expand All @@ -206,6 +215,7 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
util.Log.Infof("config: %s", p.configPath)

c.Conf.Pipe = p.pipe
c.Conf.Vvv = p.vvv
var servernames []string
if 0 < len(f.Args()) {
servernames = f.Args()
Expand Down
17 changes: 17 additions & 0 deletions commands/util.go
Expand Up @@ -19,8 +19,11 @@ package commands

import (
"fmt"
"os"
"path/filepath"

"github.com/howeyc/gopass"
homedir "github.com/mitchellh/go-homedir"
)

func getPasswd(prompt string) (string, error) {
Expand All @@ -36,3 +39,17 @@ func getPasswd(prompt string) (string, error) {
}

}

func mkdirDotVuls() error {
home, err := homedir.Dir()
if err != nil {
return err
}
dotVuls := filepath.Join(home, ".vuls")
if _, err := os.Stat(dotVuls); os.IsNotExist(err) {
if err := os.Mkdir(dotVuls, 0700); err != nil {
return err
}
}
return nil
}
1 change: 1 addition & 0 deletions config/config.go
Expand Up @@ -162,6 +162,7 @@ type Config struct {
AzureContainer string

Pipe bool
Vvv bool
Diff bool
UUID bool
}
Expand Down
25 changes: 18 additions & 7 deletions scan/executil.go
Expand Up @@ -26,6 +26,7 @@ import (
"net"
"os"
ex "os/exec"
"path/filepath"
"strings"
"syscall"
"time"
Expand All @@ -36,6 +37,7 @@ import (
"github.com/cenkalti/backoff"
conf "github.com/future-architect/vuls/config"
"github.com/future-architect/vuls/util"
homedir "github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -269,20 +271,29 @@ func sshExecExternal(c conf.ServerInfo, cmd string, sudo bool) (result execResul
return sshExecNative(c, cmd, sudo)
}

home, err := homedir.Dir()
if err != nil {
msg := fmt.Sprintf("Failed to get HOME directory: %s", err)
result.Stderr = msg
result.ExitStatus = 997
return
}
controlPath := filepath.Join(home, ".vuls", `controlmaster-%r-%h.%p`)

defaultSSHArgs := []string{
"-tt",
"-o", "StrictHostKeyChecking=yes",
"-o", "LogLevel=quiet",
"-o", "ConnectionAttempts=3",
"-o", "ConnectTimeout=10",
"-o", "ControlMaster=no",
"-o", "ControlPath=none",

// TODO ssh session multiplexing
// "-o", "ControlMaster=auto",
// "-o", `ControlPath=~/.ssh/controlmaster-%r-%h.%p`,
// "-o", "Controlpersist=30m",
"-o", "ControlMaster=auto",
"-o", fmt.Sprintf("ControlPath=%s", controlPath),
"-o", "Controlpersist=10m",
}
if conf.Conf.Vvv {
defaultSSHArgs = append(defaultSSHArgs, "-vvv")
}

args := append(defaultSSHArgs, fmt.Sprintf("%s@%s", c.User, c.Host))
args = append(args, "-p", c.Port)

Expand Down

0 comments on commit 5e1a24e

Please sign in to comment.