{"id":8308,"date":"2022-12-09T22:51:12","date_gmt":"2022-12-09T22:51:12","guid":{"rendered":"https:\/\/www.hexacorn.com\/blog\/?p=8308"},"modified":"2022-12-09T22:51:46","modified_gmt":"2022-12-09T22:51:46","slug":"marrying-client-side-windows-based-cryptencrypt-and-server-sidelinux-based-cryptopensslrsa","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2022\/12\/09\/marrying-client-side-windows-based-cryptencrypt-and-server-sidelinux-based-cryptopensslrsa\/","title":{"rendered":"Marrying client-side Windows-based CryptEncrypt and server-side,Linux-based  Crypt::OpenSSL::RSA"},"content":{"rendered":"\n<p>Time flies and it does so very quickly. The story I am about to tell you is 8 years old, but it does feel like I wrote it yesterday.<\/p>\n\n\n\n<p>In 2014 a client asked me to develop a never-seen-before prototype of a new type of an endpoint agent that would be code-minimal, position-independent, 32- and 64- architecture-aware and talk to a backend using strong encryption. Yes, kinda EDR or C2-like agent and we had discussions about using it for both blue and red team engagements, if it worked.<\/p>\n\n\n\n<p>Anyone who tried to make Windows crypto primitives talk to (typically Linux-based) server-side crypto primitives knows that it is an awful coding experience. After googling around, and trying different things I eventually developed the prototype. I can&#8217;t share the code for obvious reasons, but I can at least describe what it did.<\/p>\n\n\n\n<p>On a client side, I had a routine that would talk to the socket (not proxy aware at that time) and follow a basic data protocol exchanging encrypted data blobs with my server. The data was encrypted with a public key that only server could decrypt. Nothing really ground breaking.  <\/p>\n\n\n\n<p>What was annoyingly, frustratingly hard to develop was the actual decryption part. The server part was using Crypt::OpenSSL::RSA (yes, perl!) primitive, and I couldn&#8217;t force it to decrypt the CryptEncrypted message I was sending. <\/p>\n\n\n\n<p>After many hours of debugging and googling around I eventually figured it out. After I used CryptEncrypt I just had to reverse the data blob delivered by the function: byte, by byte. Yup, it was that simple. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Time flies and it does so very quickly. The story I am about to tell you is 8 years old, but it does feel like I wrote it yesterday. In 2014 a client asked me to develop a never-seen-before prototype &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2022\/12\/09\/marrying-client-side-windows-based-cryptencrypt-and-server-sidelinux-based-cryptopensslrsa\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[103,58,93],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/8308"}],"collection":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/comments?post=8308"}],"version-history":[{"count":2,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/8308\/revisions"}],"predecessor-version":[{"id":8310,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/8308\/revisions\/8310"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=8308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=8308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=8308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}