Skip to content

Commit

Permalink
✨ Output RAW Shellcode instead
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianqaq committed Feb 5, 2024
1 parent 0206cb5 commit 19bf99a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
19 changes: 16 additions & 3 deletions Converters/Converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ func ConvertShellcode2Hex(shellcode string, language string) (string, int) {
// Split hex shellcode into individual hex values
hexValues := strings.Split(hexShellcode, "")

formattedHexShellcode := ""
var builder strings.Builder

// Format and add "0x" in front of each pair of hex characters
for i := 0; i < len(hexValues); i += 2 {
formattedHexShellcode += "0x" + hexValues[i] + hexValues[i+1]
builder.WriteString("0x")
builder.WriteString(hexValues[i])
builder.WriteString(hexValues[i+1])

if i < len(hexValues)-2 {
formattedHexShellcode += ", "
builder.WriteString(", ")
}
}

formattedHexShellcode := builder.String()

// Calculate shellcode size in bytes
shellcodeSize := len(shellcode)

Expand Down Expand Up @@ -102,3 +107,11 @@ func AddValues2Template(operatingSystem string, template string) string {

return template
}

// CleanShellcodeString function
func CleanShellcodeString(s string) string {
s = strings.ReplaceAll(s, " ", "")
s = strings.ReplaceAll(s, "0x", "")
s = strings.ReplaceAll(s, ",", "")
return s
}
34 changes: 34 additions & 0 deletions Output/Output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package Output

import (
"Supernova/Utils"
"Supernova/Converters"
"encoding/hex"
"fmt"
"os"
)
Expand Down Expand Up @@ -59,3 +61,35 @@ func KeyDetailsFormatter(key []byte) string {
}
return formattedKey
}

// SaveShellcodeToFile function
func SaveShellcodeToFile(shellcode, filename string) error {
// Removes Spaces and the "0x" prefix from the string
shellcode = Converters.CleanShellcodeString(shellcode)

// Decodes shellcode string into byte array
data, err := hex.DecodeString(shellcode)
if err != nil {
return fmt.Errorf("Error decoding shellcode: %v", err)
}

file, err := os.Create(filename)
if err != nil {
return fmt.Errorf("Error creating file: %v", err)
}
defer file.Close()

_, err = file.Write(data)
if err != nil {
return fmt.Errorf("Error writing to file: %v", err)
}

absolutePath, err := Utils.GetAbsolutePath(filename)
if err != nil {
fmt.Println("Error:", err)
return err
}

fmt.Printf("[+] Save encrypted shellcode file to " + absolutePath + "\n\n")
return nil
}
14 changes: 11 additions & 3 deletions Supernova.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func Options() *FlagOptions {
inputFile := flag.String("i", "", "64位原始格式 Shellcode 的路径")
encryption := flag.String("enc", "", "Shellcode加密方式 (例如, ROT, XOR, RC4, AES, CHACHA20, B64XOR, B64RC4, B64AES, B64CHACHA20)")
language := flag.String("lang", "", "转换(Nim, Rust, C, CSharp, Go)格式的Shellcode")
outFile := flag.String("o", "", "输出文件名")
outFile := flag.String("o", "", "输出到文件")
variable := flag.String("v", "shellcode", "Shellcode 的变量名称")
debug := flag.Bool("d", false, "开启 Debug 模式")
key := flag.Int("k", 1, "加密的密钥长度")
Expand Down Expand Up @@ -137,7 +137,15 @@ func main() {
template := Converters.ConvertShellcode2Template(encryptedShellcode, foundLanguage, encryptedLength, options.variable)

// Print encrypted template
fmt.Printf("[+] The encrypted payload with %s:\n\n%s\n\n", strings.ToLower(options.encryption), template)
encryptionType := strings.ToLower(options.encryption)
if options.outFile == "" && encryptedLength > 100000 {
fmt.Printf("[!] Encrypted payload (%s) is too large for console display.\n\n"+
"[!] Size: %d\n\n[!] Save the output to a file using: -o filename\n\n", encryptionType, encryptedLength)
} else if options.outFile != "" {
fmt.Printf("[+] Encrypted payload with %s\n\n", encryptionType)
} else {
fmt.Printf("[+] Encrypted payload with %s\n\n%s\n\n", encryptionType, template)
}

// Guide option is enable
if options.guide {
Expand All @@ -146,7 +154,7 @@ func main() {

// Outfile option is enable
if options.outFile != "" {
err := Output.SaveOutputToFile(template, options.outFile)
err := Output.SaveShellcodeToFile(encryptedShellcode, options.outFile)
if err != nil {
fmt.Println("Error:", err)
return
Expand Down

0 comments on commit 19bf99a

Please sign in to comment.