{"id":4252,"date":"2012-04-30T10:57:00","date_gmt":"2012-04-30T18:57:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=4252"},"modified":"2012-04-30T10:58:05","modified_gmt":"2012-04-30T18:58:05","slug":"how-safe-are-credentials-in-script-packages","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2012\/04\/30\/how-safe-are-credentials-in-script-packages\/","title":{"rendered":"How safe are credentials in script packages?"},"content":{"rendered":"<p>We get that question all the time. Before we start, please note that we do not advise to <strong>ever<\/strong> put credentials as plain text into any kind of code. Use encrypted strings, store encrypted credentials in files or, if all else fails, prompt. Now, having said that we all know that sometimes schedules and pressure from \u201cabove\u201d forces you to do things you normally wouldn\u2019t do. So for the sake of argument we have created a variety of executables which use SUPERADMINUSER and SUPERSTRONGPASSWORD to run a WMI query on SUPERSECRETSERVER.<\/p>\n<p>We used <\/p>\n<ol>\n<li>VBScript\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image_thumb.png\" width=\"644\" height=\"105\"><\/a>  <\/p>\n<li>PowerShell\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image1.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image_thumb1.png\" width=\"644\" height=\"66\"><\/a>  <\/p>\n<li>C#\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image2.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image_thumb2.png\" width=\"644\" height=\"154\"><\/a>  <\/p>\n<li>C++\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image3.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image_thumb3.png\" width=\"644\" height=\"320\"><\/a> <\/p>\n<\/li>\n<\/ol>\n<p>Obviously all of these won\u2019t run in your environment unless you create a server with that name and add those credentials. <br \/>If you want to examine the resulting executable files yourself, go to <a href=\"http:\/\/www.sapien.com\/download\">www.sapien.com\/download<\/a> and look for WMIQueryExecutables.zip in the \u201cBlog Samples\u201d folder.<\/p>\n<p>Now we take all these files and open them in PrimalScript as binary files and look for the user id and password, starting with the C++ version.<\/p>\n<\/p>\n<p>And here is your password, easily visible in the binary data:<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image4.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image_thumb4.png\" width=\"644\" height=\"434\"><\/a> <\/p>\n<p>The spacing with NULL characters comes from the string being stored as unicode, so lets search for that in the C# version:<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image5.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image_thumb5.png\" width=\"644\" height=\"434\"><\/a> <\/p>\n<\/p>\n<p>As you can see, we didn\u2019t have to look far. To make matters worse, if you take a disassembly tool to a .NET exe you don\u2019t even have to read binary data:<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/SNAGHTML9cb1335.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"SNAGHTML9cb1335\" border=\"0\" alt=\"SNAGHTML9cb1335\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/SNAGHTML9cb1335_thumb.png\" width=\"644\" height=\"370\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Now let\u2019s try the script packages created by PrimalScript:<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image6.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image_thumb6.png\" width=\"644\" height=\"434\"><\/a> <\/p>\n<p>and<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image7.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/04\/image_thumb7.png\" width=\"644\" height=\"434\"><\/a> <\/p>\n<p>So you see, if you have to, absolutely <strong>have<\/strong> to put credentials somewhere, a packaged script is the way to go.<br \/>Go ahead, get the binaries and see for yourself. Here is where they are once again: Go to <a href=\"http:\/\/www.sapien.com\/download\">www.sapien.com\/download<\/a> and look for WMIQueryExecutables.zip in the \u201cBlog Samples\u201d folder.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We get that question all the time. Before we start, please note that we do not advise to ever put credentials as plain text into any kind of code. Use encrypted strings, store encrypted credentials in files or, if all else fails, prompt. Now, having said that we all know that sometimes schedules and pressure [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[27,2,705,410,24,25],"tags":[99,707,556,708,373,28,706,709,996],"class_list":["post-4252","post","type-post","status-publish","format-standard","hentry","category-ask-the-experts","category-general","category-powershell-studio-2012","category-primalscript-software-news","category-vbscript","category-windows-powershell","tag-c","tag-disassembler","tag-encryption","tag-exeutable","tag-password","tag-powershell","tag-script-package","tag-username","tag-vbscript"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/4252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=4252"}],"version-history":[{"count":3,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/4252\/revisions"}],"predecessor-version":[{"id":4257,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/4252\/revisions\/4257"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=4252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=4252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=4252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}