Skip to content

Commit b2cf388

Browse files
committed
main.go: add with-dollar flag, move output obfuscated string to function.
1 parent 573de38 commit b2cf388

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

cmd/main.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
keyFile string
1919
rawStr string
2020
noToken bool
21+
dollar bool
2122
)
2223

2324
func init() {
@@ -36,6 +37,7 @@ func init() {
3637
flag.StringVar(&keyFile, "tls-key", "key.pem", "tls private key file path")
3738
flag.StringVar(&rawStr, "obf", "", "obfuscate malicious(payload) string")
3839
flag.BoolVar(&noToken, "no-token", false, "not add random token when use obfuscate")
40+
flag.BoolVar(&dollar, "with-dollar", false, "add one dollar to the obfuscated string")
3941
flag.Parse()
4042
}
4143

@@ -56,20 +58,7 @@ func banner() {
5658
func main() {
5759
// output obfuscated string
5860
if rawStr != "" {
59-
obfuscated, rwt := log4shell.Obfuscate(rawStr, !noToken)
60-
var raw string
61-
if noToken {
62-
raw = rawStr
63-
} else {
64-
raw = rwt
65-
}
66-
fmt.Printf("raw: %s\n\n", raw)
67-
fmt.Println(obfuscated)
68-
if noToken {
69-
return
70-
}
71-
const notice = "\nEach string can only be used once, or wait %d seconds.\n"
72-
fmt.Printf(notice, log4shell.TokenExpireTime)
61+
obfuscate()
7362
return
7463
}
7564

@@ -110,6 +99,31 @@ func main() {
11099
checkError(err)
111100
}
112101

102+
func obfuscate() {
103+
var (
104+
obfuscated string
105+
rawWithToken string
106+
)
107+
if dollar {
108+
obfuscated, rawWithToken = log4shell.ObfuscateWithDollar(rawStr, !noToken)
109+
} else {
110+
obfuscated, rawWithToken = log4shell.Obfuscate(rawStr, !noToken)
111+
}
112+
var raw string
113+
if noToken {
114+
raw = rawStr
115+
} else {
116+
raw = rawWithToken
117+
}
118+
fmt.Printf("raw: %s\n\n", raw)
119+
fmt.Println(obfuscated)
120+
if noToken {
121+
return
122+
}
123+
const notice = "\nEach string can only be used once, or wait %d seconds.\n"
124+
fmt.Printf(notice, log4shell.TokenExpireTime)
125+
}
126+
113127
func checkError(err error) {
114128
if err != nil {
115129
log.Fatalln("[error]", err)

0 commit comments

Comments
 (0)