{"id":56,"date":"2018-03-06T00:19:21","date_gmt":"2018-03-05T23:19:21","guid":{"rendered":"https:\/\/cybercop-training.ch\/?p=56"},"modified":"2018-03-06T00:19:21","modified_gmt":"2018-03-05T23:19:21","slug":"a-little-bit-of-powershell-forensic-p1","status":"publish","type":"post","link":"https:\/\/cybercop-training.ch\/?p=56","title":{"rendered":"A little bit of Powershell Forensic P1"},"content":{"rendered":"<p>Powershell is a powerful tool for every Sysadmin! Just few days ago I&#8217;ve discovered the <a href=\"https:\/\/cqureacademy.com\/blog\" target=\"_blank\" rel=\"noopener\">Blog of CqureAcademy<\/a> where Paula gives this nice <a href=\"https:\/\/cqureacademy.com\/blog\/forensics\/how-to-recover-deleted-files-from-the-drive\" target=\"_blank\" rel=\"noopener\">introduction into Powershell Forensic<\/a>. This looks amazing and catched immediately my attention. I didn&#8217;t know about that\u00a0<a href=\"https:\/\/powerforensics.readthedocs.io\/en\/latest\/moduleinstall\/\" target=\"_blank\" rel=\"noopener\">particular Module<\/a> before and decided to try it out.<\/p>\n<p>In my case I don&#8217;t attach a vhdx file. I&#8217;ll use a USB flashdrive where I&#8217;ll try the file recovery.<\/p>\n<pre class=\"code\">Let's go and start. First I'll start the powershell with admin privileges and install the module.<strong>\r\n\r\nFind-Module -Name *Forensic*\r\nInstall-Module PowerForensicsv2\r\n<a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-57\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell1.png\" alt=\"\" width=\"972\" height=\"456\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell1.png 972w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell1-300x141.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell1-768x360.png 768w\" sizes=\"auto, (max-width: 972px) 100vw, 972px\" \/><\/a><\/strong><\/pre>\n<hr \/>\n<pre class=\"code\">Now let's import the Module and get a list of all the cmdlets\r\n<strong>Import-Module PowerForensicsv2\r\nGet-Command -Module PowerForensicsv2\r\n <a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-62\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell2.png\" alt=\"\" width=\"978\" height=\"964\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell2.png 978w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell2-300x296.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell2-768x757.png 768w\" sizes=\"auto, (max-width: 978px) 100vw, 978px\" \/><\/a><\/strong><\/pre>\n<hr \/>\n<pre class=\"code\">For test puproses I did copy some portables on my USB flashdrive and delete them.\r\nLet's see what we get with the first command:\r\n\r\n<strong>Get-ForensicFileRecord -VolumeName E: | where-object {$_.Deleted}<\/strong>\r\n<a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-65\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell3.png\" alt=\"\" width=\"977\" height=\"702\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell3.png 977w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell3-300x216.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell3-768x552.png 768w\" sizes=\"auto, (max-width: 977px) 100vw, 977px\" \/><\/a><\/pre>\n<hr \/>\n<pre class=\"code\">Now we can see the portables and that they're marked as deleted. We notice that there is for every deleted file a RecordNumber.\r\nLet's have a closer look on this:\r\n\r\n<strong>Get-ForensicFileRecord -VolumeName E: -Index 39<\/strong>\r\n<a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-67\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell4.png\" alt=\"\" width=\"978\" height=\"509\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell4.png 978w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell4-300x156.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell4-768x400.png 768w\" sizes=\"auto, (max-width: 978px) 100vw, 978px\" \/><\/a>\r\nNow let's put that command in a variable and read out the file attributes:\r\n<strong>$fr=Get-ForensicFileRecord -VolumeName E: -Index 39<\/strong>\r\n<strong>$fr.Attribute<\/strong>\r\n<a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-68\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell5.png\" alt=\"\" width=\"838\" height=\"737\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell5.png 838w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell5-300x264.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell5-768x675.png 768w\" sizes=\"auto, (max-width: 838px) 100vw, 838px\" \/><\/a>\r\nInteressting for us is DataRun from which we can gain some more information about the file itself.<\/pre>\n<hr \/>\n<pre class=\"code\"><strong>$fd=$fr.Attribute | where-Object {$_.name -eq 'Data'}<\/strong>\r\n<strong>$fd.DataRun<\/strong>\r\n<a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-70\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell6.png\" alt=\"\" width=\"982\" height=\"278\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell6.png 982w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell6-300x85.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell6-768x217.png 768w\" sizes=\"auto, (max-width: 982px) 100vw, 982px\" \/><\/a>\r\nDataRun shows us the starting cluster and the cluster length which tells us how big the file is. \r\nNow let's display some informations about the target volume e: and try to recover the file<\/pre>\n<hr \/>\n<pre class=\"code\"><strong>get-ForensicVolumeBootRecord -Volume e:<\/strong>\r\n<a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-71\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell7.png\" alt=\"\" width=\"978\" height=\"459\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell7.png 978w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell7-300x141.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell7-768x360.png 768w\" sizes=\"auto, (max-width: 978px) 100vw, 978px\" \/>\r\n<\/a>As you can see we got BytesPerCluster. Togehter with the Datarun information we try to recover the file<\/pre>\n<hr \/>\n<pre class=\"code\"><strong>Invoke-ForensicDD -InFile \\\\.\\e: -offset (1538*4096) -Blocksize (121*4096) -Count 1 -Outfile C:\\temp\\test.exe\r\n<a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-72\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell8.png\" alt=\"\" width=\"980\" height=\"565\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell8.png 980w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell8-300x173.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/powershell8-768x443.png 768w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/a>\r\n<\/strong>Now let's go to the directory and check oure restored file:\r\n<a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/putty_restored.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-73\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/putty_restored-1024x473.png\" alt=\"\" width=\"1024\" height=\"473\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/putty_restored-1024x473.png 1024w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/putty_restored-300x139.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/putty_restored-768x355.png 768w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2018\/03\/putty_restored.png 1196w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a>\r\nAs you can see, putty.exe is succesfull restored.\r\nSoon I'll add a short Part2 with another exercise ;-)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Powershell is a powerful tool for every Sysadmin! Just few days ago I&#8217;ve discovered the Blog of CqureAcademy where Paula gives this nice introduction into <a class=\"mh-excerpt-more\" href=\"https:\/\/cybercop-training.ch\/?p=56\" title=\"A little bit of Powershell Forensic P1\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":2,"featured_media":59,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,9,10],"tags":[13,12,11],"class_list":["post-56","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-forensic","category-powershell","category-windows-security","tag-filerestore","tag-forensic","tag-powershell"],"_links":{"self":[{"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/posts\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=56"}],"version-history":[{"count":8,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions"}],"predecessor-version":[{"id":74,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions\/74"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/media\/59"}],"wp:attachment":[{"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}