If we add stub + *.enc file to SFX we can have our stub do all the work for us. :)
I would suggest to anyone storing keys inside a binary to compress the executable using something other than UPX or ASPack. ;-) keys get gen all the time so it's best to use something with tons of instructions for anti-debugging, strip TLS, exports, and CRC protection and aPlib for compression.
Dillon's code reading from CryptoPP::ArraySource as opposed to CryptoPP::FileSource
void stubClass::LoadKey(const char *bufferPub, const char *bufferPri) {
CryptoPP::ArraySource(bufferPub, true,
new CryptoPP::StringSink(pubString));
CryptoPP::ArraySource(bufferPri, true,
new CryptoPP::StringSink(priString));
}
Hugo's class using CryptoPP::FileSource
/*
void stubClass::LoadKey(const char *pubFilename, const char *privFilename) {
CryptoPP::FileSource (pubFilename, true,
new CryptoPP::StringSink(pubString));
CryptoPP::FileSource (privFilename, true,
new CryptoPP::StringSink(priString));
}
*/
We can store our keys in bufferPub and bufferPri and call this from the main() in our stub.
const char bufferPri[]="308..."
const char bufferPub[]="308..."
int main() {
char EFile[]="dob.enc";
char DFile[]="dec.exe";
stubClass stubDecrypt;
// grab our keys from memory.
stubDecrypt.LoadKey(bufferPub,bufferPri);
// decrypt our file
stubDecrypt.AES_CTR_Decrypt(EFile, DFile);
return 0;
}
thanks Hugo!
linked back to the original thread where Hugo posted his class.
regards,
Dillon Beresford
> I'll look around for "Wei's Instructions" on how to build the library
> because so far it has not been a pleasant experience.
You might also want to look at
http://www.codeproject.com/KB/tips/CryptoPPIntegration.aspx.
> I got to a stage where I need it to be more secure, so I'm taking
> the opportunity here to expand my horizons into cryptography.
> ...I want to add a final encryption phase to this nightly build.
Confidentiality (encryption) alone is an incomplete solution. You must
also ensure the data has not been altered. In the case of
communications, TCP/IP provides mechanisms to detect transmission
errors. However, they have no cryptographic properties. So if an
attacker (which controls the network) decides to modify your encrypted
data, TCP/IP will most likely not detect it.
Standard practice is Encrypt then Authenticate. One of the early works
is "The Order of Encryption and Authentication for Protecting
Communications (Or: How Secure is SSL?)" by Hugo Krawczyk.
NIST (based on IEEE Wireless LAN group) recommends CCM. Crypto++ does
not incorporate CCM at this point (Wei: hint, hint). However, if you
look at default.h, you will find DefaultEncryptorWithMAC and
DefaultDecryptorWithMAC. The composition does suffer from
cryptographic defects. But if you were willing to use encryption
alone, you will find this construction orders of magnitude stronger.
But again, it is still lacking and there are better alternatives.
Wei shows us how to use DefaultEncryptorWithMAC in test.cpp by way of
EncryptFile( ) and EncryptString( ).
DefaultEncryptorWithMAC uses the following typedefs, which you will
probably want to change to AES and a SHA-2 hash. If you favor European
standards, Camellia and Whirlpool might be your choices.
typedef DES_EDE2 Default_BlockCipher;
typedef SHA DefaultHashModule;
typedef HMAC<DefaultHashModule> DefaultMAC;
> (*) Please correct me if I'm wrong here: I believe I will need to
> embed the private key into client.exe...
Key exchange and key management is another can of worms.
Jeff
(Sorry about addressing Dillon last time. My mistake.)
> Hi there Mr. Walton,
Just jeff. No pretension here.
> So I don't know if 'default' has a special meaning in cryptography.
> To me, 'default' means something that is X today but may be Y
> tomorrow.
Definitely a moving target. Triple DES is a 64 bit cipher which offers
little security today. Hence the reason for AES or Camellia (128 bit
ciphers). NIST recommends AES, the ISO has adopted Camellia. AES gets
a lot of attention. But Camellia is well regarded. See
http://www.ntt.co.jp/news/news05e/0505/050526.html.
SHA and SHA1 are 128 and 160 bit hash functions. NIST recommends the
SHA-2 family of hashes for new application. SHA-2 is mandatory in 2010
and after. SHA-2 include SHA-256, SHA-384, and SHA-512. I don't know
what NESSIE or the ISO recommends, but I would expect that a 256 bit
version of Whirlpool is in the offering.
> Thus, so far I avoided using anything that has a 'default' in it.
DefaultEncryptorWithMAC is a convenient construction with limitations.
If you prefer, you can name it AesEncryptionWithMac (after changing
the typedefs). You must perform both message encryption and message
authentication. Encrypt then Authenticate applies to both secure
communications and on-disk file encrpytion. The point is that
encryption alone is not a solution,* AesEncryptionWithMac has
limitations, and CCM is probably what you require.
I have a Crypto++ implementation of CCM, but it does not do the
library justice. So I keep it to myself and hope that Wei provides one
in the future. The nice thing about Crypto++ is modularity. Once Wei
provides CCM, you will be able to plug in AES in the United States,
and Camellia in Europe (presuming you have faith in CCM).
> My up-to-date knowledge in cryptography relies upon your introduction
> article on CodeProject
Keep in mind these are gentle introductions. So if you look at the
Block Cipher article, it only provides information on the ciphers and
how to use them with Crypto++. It does not offer the whole picture.
This is similar to the way C++ sample code is presented without
parameter validation and exception handling.
> I really appreciate the hard work you all put into Crypto++.
Thanks. I try to help others so that they do not waste time with my
past mistakes.
Jeff
* Section 9.6 of Handbook of Applied Cryptography states we can use
E_k(m || hm)) for Confidentiality and Integrity. I used it for years
and later found that it suffered cryptographic defects also.
On 2/1/09, Avi <skydi...@gmail.com> wrote:
>
> Hi there Mr. Walton,
>
> > You might also want to look at http://www.codeproject.com/KB/tips/CryptoPPIntegration.aspx.
> I plan to #define some macro that will be used to compile just
> AES_CTR_Encrypt and embed the public key for build_db.exe and will
> compile just AES_CTR_Decrypt and embed just the private key in
> client.exe.
AES is a symmetric cipher. There is no notion of public keys and
private keys in the algorithm. If you want to protect you symmetric
key (generated offline - not exchanged - and hard coded into the
executables, you might also look at RFC 3394: Advanced Encryption
Standard (AES) Key Wrap Algorithm.
> (*) I reinstalled crypto552 and built it properly via the .dsw file,
> reinstalled dobrexor, linked to cryptopp and rebuilt and I still get
> the same crash.
Does Crypto++ pass its validation test? I believe the command is "cryptest v".
> P:\CryptoPP\dobrexor\dobclass.cpp(102) : fatal error C1001: INTERNAL
> COMPILER ERROR
Haven't seen this show its head in quite some time. Last time was with
VC6.0. If you are using 6.0, have you applied Microsoft's processor
patch?
> CryptoPP::FileSink* fs = new CryptoPP::FileSink(pubFilename);
> CryptoPP::StringSource(pubString, true, fs);
> CryptoPP::StringSource(priString, true, new CryptoPP::FileSink
> (privFilename));
When you pass variable fs to StringSource, StringSource owns it an
will delete it (the behavior is noted in ReadMe.txt if I recall
correctly). Are you performing a double delete to cause the crash?
Jeff
On 2/1/09, Avi <skydi...@gmail.com> wrote:
>