{"id":1053,"date":"2013-07-16T16:17:40","date_gmt":"2013-07-16T15:17:40","guid":{"rendered":"http:\/\/www.phillips321.co.uk\/?p=1053"},"modified":"2013-07-16T16:18:30","modified_gmt":"2013-07-16T15:18:30","slug":"simple-python-code-to-create-an-eicar-virus","status":"publish","type":"post","link":"https:\/\/www.phillips321.co.uk\/2013\/07\/16\/simple-python-code-to-create-an-eicar-virus\/","title":{"rendered":"Simple python code to create an eicar virus"},"content":{"rendered":"<p>So it&#8217;s annoying when you&#8217;re testing AV and you need to create an <a href=\"http:\/\/en.wikipedia.org\/wiki\/EICAR_test_file\" target=\"_blank\">eicar virus<\/a>. Usually the AV will keep deleting the file and your text string.<\/p>\n<p>This simple code is given the file name and will produce the output file. The benefit of using this script is that the eicar string is not actually stored inside the script as clear text.<\/p>\n<div class=\"codecolorer-container python vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/><\/div><\/td><td><div class=\"python codecolorer\"><span class=\"co1\">#!\/usr\/bin\/env python<\/span><br \/>\n<span class=\"co1\"># Author: phillips321<\/span><br \/>\n<span class=\"co1\"># Site: www.phillips321.co.uk<\/span><br \/>\n<span class=\"co1\"># Version: 0.1<\/span><br \/>\n<span class=\"co1\"># About: Creates a file containing eicar test string<\/span><br \/>\n<br \/>\n<span class=\"kw1\">import<\/span> <span class=\"kw3\">sys<\/span><span class=\"sy0\">,<\/span> <span class=\"kw3\">time<\/span><br \/>\n<span class=\"kw1\">try<\/span>:<br \/>\n&nbsp; &nbsp; filename<span class=\"sy0\">=<\/span><span class=\"kw3\">sys<\/span>.<span class=\"me1\">argv<\/span><span class=\"br0\">&#91;<\/span><span class=\"nu0\">1<\/span><span class=\"br0\">&#93;<\/span><br \/>\n<span class=\"kw1\">except<\/span>:<br \/>\n&nbsp; &nbsp; filename<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;eicar.txt&quot;<\/span><br \/>\neicarhex<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;58354f2150254041505b345c505a58353428505e2937434329377d2445494341522d5354414e444152442d414e544956495255532d544553542d46494c452124482b482a&quot;<\/span><br \/>\n<br \/>\n<span class=\"kw1\">try<\/span>:<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">print<\/span> <span class=\"st0\">&quot;Writing to %s...&quot;<\/span> % filename<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span> l <span class=\"kw1\">in<\/span> eicarhex.<span class=\"me1\">decode<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;hex&quot;<\/span><span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">sys<\/span>.<span class=\"me1\">stdout<\/span>.<span class=\"me1\">write<\/span><span class=\"br0\">&#40;<\/span>l<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">time<\/span>.<span class=\"me1\">sleep<\/span><span class=\"br0\">&#40;<\/span><span class=\"nu0\">0.05<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">print<\/span> <span class=\"st0\">&quot;<span class=\"es0\">\\n<\/span>Complete&quot;<\/span><br \/>\n&nbsp; &nbsp; fdesc <span class=\"sy0\">=<\/span> <span class=\"kw2\">open<\/span><span class=\"br0\">&#40;<\/span>filename<span class=\"sy0\">,<\/span> <span class=\"st0\">&quot;w&quot;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"kw1\">except<\/span>:<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">print<\/span> <span class=\"st0\">&quot;Unable to write to eicar.txt&quot;<\/span><br \/>\n<span class=\"kw1\">else<\/span>: <br \/>\n&nbsp; &nbsp; fdesc.<span class=\"me1\">write<\/span><span class=\"br0\">&#40;<\/span>eicarhex.<span class=\"me1\">decode<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;hex&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; fdesc.<span class=\"me1\">close<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n","protected":false},"excerpt":{"rendered":"<p>So it&#8217;s annoying when you&#8217;re testing AV and you need to create an eicar virus. Usually the AV will keep deleting the file and your text string. This simple code is given the file name and will produce the output file. The benefit of using this script is that the eicar string is not actually [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[381,111,383,382],"_links":{"self":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/1053"}],"collection":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/comments?post=1053"}],"version-history":[{"count":2,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/1053\/revisions"}],"predecessor-version":[{"id":1055,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/1053\/revisions\/1055"}],"wp:attachment":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/media?parent=1053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/categories?post=1053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/tags?post=1053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}