Skip to content

Commit

Permalink
Merge pull request #310 from lunasec-io/cli-ux
Browse files Browse the repository at this point in the history
Cli ux
  • Loading branch information
breadchris committed Dec 15, 2021
2 parents 58e1478 + 17b7b4e commit f92099d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 6 deletions.
4 changes: 3 additions & 1 deletion tools/log4shell/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ builds:
- windows
- darwin
archives:
- replacements:
- format: binary
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64

checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
32 changes: 32 additions & 0 deletions tools/log4shell/constants/colorize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2021 by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package constants

type TerminalColor int

const (
ColorBlack TerminalColor = iota + 30
ColorRed
ColorGreen
ColorYellow
ColorBlue
ColorMagenta
ColorCyan
ColorWhite

ColorBold = 1
ColorDarkGray = 90
)

2 changes: 1 addition & 1 deletion tools/log4shell/constants/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
//
package constants

const Version = "1.1.0"
const Version = "1.1.1"
10 changes: 8 additions & 2 deletions tools/log4shell/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"encoding/json"
"fmt"
"github.com/lunasec-io/lunasec/tools/log4shell/constants"
"github.com/lunasec-io/lunasec/tools/log4shell/patch"
"github.com/lunasec-io/lunasec/tools/log4shell/scan"
Expand Down Expand Up @@ -44,7 +45,12 @@ func enableGlobalFlags(c *cli.Context) {
jsonFlag := c.Bool("json")
if !jsonFlag {
// pretty print output to the console if we are not interested in parsable output
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
consoleOutput := zerolog.ConsoleWriter{Out: os.Stderr}
consoleOutput.FormatFieldName = func(i interface{}) string {
return fmt.Sprintf("\n\t%s: ", util.Colorize(constants.ColorBlue, i))
}
log.Logger = log.Output(consoleOutput)

}
}

Expand Down Expand Up @@ -93,7 +99,7 @@ func hotpatchCommand(c *cli.Context) error {

log.Info().
Msg("Starting Log4Shell hotpatch LDAP and payload servers")

log.Info().Msgf("Once both servers have started, use payload string: '${jndi:ldap://%s:1389/a}' to hotpatch", ip)
hotpatchServer.Start()
hotpatchPayloadServer.Start()

Expand Down
3 changes: 2 additions & 1 deletion tools/log4shell/patch/hotpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ func (s *HotpatchLDAPServer) Start() {
addr := "0.0.0.0:1389"
log.Info().
Str("addr", addr).
Msg("starting hotpatch server")
Msg("Started hotpatch server")
err := s.server.ListenAndServe(addr)
if err != nil {
log.Error().
Err(err).
Msg("unable to start ldap server")
panic(err)
}
log.Info().Msg("HotPatch Server Started")
}()
}

Expand Down
2 changes: 1 addition & 1 deletion tools/log4shell/patch/payloadserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *HotpatchPayloadServer) Start() {
addr := fmt.Sprintf("0.0.0.0:%d", constants.HotpatchServerPort)
log.Info().
Str("addr", addr).
Msg("starting hotpatch payload server")
Msg("Started hotpatch payload server")
err := http.ListenAndServe(addr, nil)
if err != nil {
log.Error().
Expand Down
26 changes: 26 additions & 0 deletions tools/log4shell/util/colorize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021 by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package util

import (
"fmt"
"github.com/lunasec-io/lunasec/tools/log4shell/constants"
)

// colorize returns the string s wrapped in ANSI code c, unless disabled is true.
func Colorize(c constants.TerminalColor, s interface{}) string {
return fmt.Sprintf("\x1b[%dm%v\x1b[0m", c, s)
}

0 comments on commit f92099d

Please sign in to comment.