Skip to content

Commit

Permalink
🔀 Merge branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianqaq committed Mar 1, 2024
1 parent 3156f9d commit 71c850c
Show file tree
Hide file tree
Showing 13 changed files with 842 additions and 701 deletions.
31 changes: 21 additions & 10 deletions Arguments/Arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ArgumentLength(versionFlag bool) {
// If arguments are more than 2
} else if len(os.Args) > 2 {
// if versionFlag is enabled
if versionFlag != false {
if versionFlag {
logger.Fatal("You cannot use the -version flag in conjunction with other arguments.")
}
}
Expand All @@ -30,7 +30,7 @@ func ShowVersion(version string, versionFlag bool) {
// if arguments are 2
if len(os.Args) == 2 {
// if versionFlag is enabled
if versionFlag != false {
if versionFlag {
fmt.Printf("[+] Current version: " + version + "\n\n")
os.Exit(0)
} else {
Expand All @@ -49,9 +49,7 @@ func ArgumentEmpty(statement string, option int) {
case 1:
logger.Fatal("Please provide a path to a file containing raw 64-bit shellcode.")
case 2:
logger.Fatal("Please provide a valid value for the programming language (e.g., C++, CSharp, Rust, Nim, Go).")
case 3:
logger.Fatal("Please provide a valid value for the encryption (e.g., ROT, XOR, RC4, AES, CHACHA20, B64XOR, B64RC4, B64AES, B64CHACHA20).")
logger.Fatal("Please provide a valid value for the programming language (e.g., C, CSharp, Rust, Nim, Go, Python).")
default:
logger.Fatal("Invalid option specified for ArgumentEmpty function.")
}
Expand All @@ -60,27 +58,40 @@ func ArgumentEmpty(statement string, option int) {

// ValidateArgument function
func ValidateArgument(argName string, argValue string, validValues []string) string {
if strings.ToLower(argValue) == "golang" {
argValue = "Go"
}

for _, valid := range validValues {
if strings.ToLower(argValue) == strings.ToLower(valid) {
if strings.EqualFold(strings.ToLower(argValue), strings.ToLower(valid)) {
valid = strings.ToLower(valid)
return valid
}
}

fmt.Printf("[!] Invalid value '%s' for argument '%s'. Valid values are: %v\n", argValue, argName, validValues)
os.Exit(1)
return ""
}

// ValidateKeySize function
func ValidateKeySize(key int, encryption string) {
func ValidateKeySize(key int, encryption string) int {
logger := log.New(os.Stderr, "[!] ", 0)
if key <= 0 {
logger.Fatal("Please provide a valid key value for the size...\n")
}

if encryption == "aes" {
if key > 1 {
logger.Fatal("The AES cipher does not require a separate 'key' argument. It employs a standard key length of 32-byte. Please remove it...\n")
if strings.ToLower(encryption) == "aes" || strings.ToLower(encryption) == "b64aes" {
switch key {
case 128, 16:
key = 16
case 192, 24:
key = 24
case 256, 32:
key = 32
default:
logger.Fatal("Provide a valid AES key:\n\nFor AES-128-CBC:\n\n-k 128 or -k 16\n\nFor AES-192-CBC:\n\n-k 192 or -k 24\n\nFor AES-256-CBC:\n\n-k 256 or -k 32\n\n")
}
}
return key
}
51 changes: 37 additions & 14 deletions Converters/Converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ func ConvertShellcode2Hex(shellcode string, language string) (string, int) {

var builder strings.Builder

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

if i < len(hexValues)-2 {
builder.WriteString(", ")
if language == "python" {
for i := 0; i < len(hexValues); i += 2 {
builder.WriteString("\\x")
builder.WriteString(hexValues[i])
builder.WriteString(hexValues[i+1])
}
} else {
// Format and add "0x" in front of each pair of hex characters
for i := 0; i < len(hexValues); i += 2 {
builder.WriteString("0x")
builder.WriteString(hexValues[i])
builder.WriteString(hexValues[i+1])
if i < len(hexValues)-2 {
builder.WriteString(", ")
}
}
}

Expand Down Expand Up @@ -53,8 +60,13 @@ func ConvertShellcode2Template(shellcode string, language string, length int, va
template := fmt.Sprintf(`let %s: [u8; %d] = [%s];`, variable, length, shellcode)
return template
case "go":
template := fmt.Sprintf(`%s := []byte{%s}`, variable, shellcode)
template := fmt.Sprintf(`%s := []byte{%s};`, variable, shellcode)
return template
case "python":
template := fmt.Sprintf(`%s = b"%s"`, variable, shellcode)
return template
case "raw":
return shellcode
default:
fmt.Println("[!] Unsupported programming language:", language)
os.Exit(1)
Expand Down Expand Up @@ -88,20 +100,31 @@ func FormatKeysToHex(byteArray []byte) string {
}

// FormatShellcode function
func FormatShellcode(encryptedShellcode []byte) string {
func FormatShellcode(encryptedShellcode []byte, language string) string {
var formattedShellcode []string
var shellcodeFormatted string

for _, b := range encryptedShellcode {
formattedShellcode = append(formattedShellcode, fmt.Sprintf("0x%02x", b))
if language == "python" {
formattedShellcode = append(formattedShellcode, fmt.Sprintf("\\x%02x", b))
} else {
formattedShellcode = append(formattedShellcode, fmt.Sprintf("0x%02x", b))
}
}

shellcodeFormatted := strings.Join(formattedShellcode, ", ")
// Combine elements into a single string
if language == "python" {
shellcodeFormatted = strings.Join(formattedShellcode, "")
} else {
shellcodeFormatted = strings.Join(formattedShellcode, ", ")
}

return shellcodeFormatted
}

// AddValues2Template function
func AddValues2Template(operatingSystem string, template string) string {
if strings.ToLower(operatingSystem) == "linux" {
if strings.ToLower(operatingSystem) == "linux" || strings.ToLower(operatingSystem) == "windows" {
template = "#include <Windows.h>" + template
}

Expand All @@ -114,4 +137,4 @@ func CleanShellcodeString(s string) string {
s = strings.ReplaceAll(s, "0x", "")
s = strings.ReplaceAll(s, ",", "")
return s
}
}

0 comments on commit 71c850c

Please sign in to comment.