diff --git a/cli/parser.go b/cli/parser.go
@@ -107,6 +107,20 @@ func GetParser(opts *Options) *cobra.Command {
panic(err)
}
template = tools.GetXORTemplate()
+
+ case EncKindBLF:
+ encrypted, err = tools.EncryptBlowfish(shellcode, []byte(opts.Key))
+ if err != nil {
+ fmt.Println("[!] Could not encrypt with Blowfish")
+ panic(err)
+ }
+
+ /* Running `go get golang.org/x/crypto/blowfish in MYPH_TMP_DIR` */
+ execCmd := exec.Command("go", "get", "golang.org/x/crypto/blowfish")
+ execCmd.Dir = MYPH_TMP_DIR
+
+ _, _ = execCmd.Output()
+ template = tools.GetBlowfishTemplate()
}
/* write decryption routine template */
@@ -171,7 +185,7 @@ func GetParser(opts *Options) *cobra.Command {
cmd.PersistentFlags().StringVarP(&opts.Target, "process", "p", defaults.Target, "target process to inject shellcode to")
cmd.PersistentFlags().StringVarP(&opts.Technique, "technique", "t", defaults.Technique, "shellcode-loading technique (allowed: CRT, CreateThread)")
- cmd.PersistentFlags().VarP(&opts.Encryption, "encryption", "e", "encryption method. (allowed: AES, XOR)")
+ cmd.PersistentFlags().VarP(&opts.Encryption, "encryption", "e", "encryption method. (allowed: AES, XOR, blowfish)")
cmd.PersistentFlags().StringVarP(&opts.Key, "key", "k", "", "encryption key, auto-generated if empty. (if used by --encryption)")
return cmd
diff --git a/cli/types.go b/cli/types.go
@@ -11,7 +11,7 @@ type technique string
const (
EncKindAES encKind = "AES"
EncKindXOR encKind = "XOR"
- EncKindBLF encKind = "Blowfish"
+ EncKindBLF encKind = "blowfish"
CRT technique = "CRT"
CreateThread technique = "CreateThread"
@@ -25,11 +25,11 @@ func (e *encKind) String() string {
// Set must have pointer receiver so it doesn't change the value of a copy
func (e *encKind) Set(v string) error {
switch v {
- case "AES", "XOR":
+ case "AES", "XOR", "blowfish":
*e = encKind(v)
return nil
default:
- return errors.New("must be one of \"AES\" or \"XOR\"\n\n")
+ return errors.New("must be one of \"AES\", \"blowfish\" or \"XOR\"\n\n")
}
}
diff --git a/tools/crypting.go b/tools/crypting.go
@@ -21,10 +21,10 @@ import (
"crypto/cipher"
)
-func Decrypt(toDecrypt []byte, key []byte) (error, []byte) {
+func Decrypt(toDecrypt []byte, key []byte) ([]byte, error) {
dcipher, err := blowfish.NewCipher(key)
if err != nil {
- return err, []byte{}
+ return []byte{}, err
}
div := toDecrypt[:blowfish.BlockSize]
@@ -32,7 +32,7 @@ func Decrypt(toDecrypt []byte, key []byte) (error, []byte) {
dcbc := cipher.NewCBCDecrypter(dcipher, div)
dcbc.CryptBlocks(decrypted, decrypted)
- return nil, decrypted
+ return decrypted, nil
}
`)
}
@@ -85,10 +85,24 @@ func Decrypt(toDecrypt []byte, key []byte) ([]byte, error) {
`)
}
-func EncryptBlowfish(toCrypt []byte, key []byte) (error, []byte) {
+func EncryptBlowfish(toCrypt []byte, key []byte) ([]byte, error) {
+
+ /*
+ let's add the required padding :)~
+ source: https://stackoverflow.com/a/46747195
+ */
+
+ modulus := len(toCrypt) % blowfish.BlockSize
+ if modulus != 0 {
+ padlen := blowfish.BlockSize - modulus
+ for i := 0; i < padlen; i++ {
+ toCrypt = append(toCrypt, 0)
+ }
+ }
+
ecipher, err := blowfish.NewCipher(key)
if err != nil {
- return nil, []byte{}
+ return []byte{}, err
}
ciphertext := make([]byte, blowfish.BlockSize+len(toCrypt))
@@ -96,13 +110,13 @@ func EncryptBlowfish(toCrypt []byte, key []byte) (error, []byte) {
ecbc := cipher.NewCBCEncrypter(ecipher, eiv)
ecbc.CryptBlocks(ciphertext[blowfish.BlockSize:], toCrypt)
- return nil, ciphertext
+ return ciphertext, nil
}
-func DecryptBlowfish(toDecrypt []byte, key []byte) (error, []byte) {
+func DecryptBlowfish(toDecrypt []byte, key []byte) ([]byte, error) {
dcipher, err := blowfish.NewCipher(key)
if err != nil {
- return err, []byte{}
+ return []byte{}, err
}
div := toDecrypt[:blowfish.BlockSize]
@@ -110,7 +124,7 @@ func DecryptBlowfish(toDecrypt []byte, key []byte) (error, []byte) {
dcbc := cipher.NewCBCDecrypter(dcipher, div)
dcbc.CryptBlocks(decrypted, decrypted)
- return nil, decrypted
+ return decrypted, nil
}
func EncryptXOR(toEncrypt []byte, key []byte) ([]byte, error) {
| | |