Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Feat/makefile #56

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all:
go run log4jscanner.go

build:
go build -o log4jscanner

52 changes: 52 additions & 0 deletions jar/backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2021 Google LLC
//
// 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
//
// https://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 jar

import (
"bufio"
"fmt"
"io"
"log"
"os"
)

func CreateDirectoryifNotExist(dir string) {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err = os.Mkdir(dir, 0755)
if err != nil {
log.Fatal(err)
}
}
}

func Backup(dstFileName string, srcFileName string) (written int64, err error) {
srcFile, err := os.Open(srcFileName)
if err != nil {
fmt.Printf("open file error = %v\n", err)
}
defer srcFile.Close()

reader := bufio.NewReader(srcFile)

dstFile, err := os.OpenFile(dstFileName, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Printf("open file error = %v\n", err)
}

writer := bufio.NewWriter(dstFile)

defer dstFile.Close()
return io.Copy(writer, reader)
}
6 changes: 6 additions & 0 deletions log4jscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Flags:
-f, --force Don't skip network and userland filesystems. (smb,nfs,afs,fuse)
-w, --rewrite Rewrite vulnerable JARs as they are detected.
-v, --verbose Print verbose logs to stderr.
-b, --backup Suffix to use to backup a file when rewriting (.bak)

`)
}
Expand Down Expand Up @@ -74,8 +75,10 @@ func main() {
flag.BoolVar(&w, "w", false, "")
flag.BoolVar(&verbose, "verbose", false, "")
flag.BoolVar(&v, "v", false, "")

flag.BoolVar(&force, "force", false, "")
flag.BoolVar(&f, "f", false, "")

flag.Func("s", "", appendSkip)
flag.Func("skip", "", appendSkip)
flag.Usage = usage
Expand All @@ -94,10 +97,12 @@ func main() {
if w {
rewrite = w
}

log.SetFlags(log.LstdFlags | log.Lshortfile)
logf := func(format string, v ...interface{}) {
if verbose {
log.Printf(format, v...)

}
}
seen := 0
Expand Down Expand Up @@ -140,6 +145,7 @@ func main() {
},
}


for _, dir := range dirs {
logf("Scanning %s", dir)
if err := walker.Walk(dir); err != nil {
Expand Down