Board logo

标题: [转载代码] [PowerShell每日技巧]读写NTFS流(20140127) [打印本页]

作者: DAIC    时间: 2014-2-12 11:11     标题: [PowerShell每日技巧]读写NTFS流(20140127)

When a file is stored on a drive with NTFS file system, you can attach data streams to it to store hidden information.

Here is a sample that hides PowerShell code in an NTFS stream of a script. When you run this code, it creates a new PowerShell script file on your desktop, and opens the file in the ISE editor:
  1. $path = "$home\Desktop\secret.ps1"
  2. $secretCode = {
  3.   Write-Host -ForegroundColor Red 'This is a miracle!';
  4.   [System.Console]::Beep(4000,1000)
  5. }
  6. Set-Content -Path $path -Value '(Invoke-Expression ''[ScriptBlock]::Create((Get-Content ($MyInvocation.MyCommand.Definition) -Stream SecretStream))'').Invoke()'
  7. Set-Content -Path $path -Stream SecretStream -Value $secretCode
  8. ise $path
复制代码
The new file will expose code like this:
  1. (Invoke-Expression '[ScriptBlock]::Create((Get-Content ($MyInvocation.MyCommand.Definition) -Stream SecretStream))').Invoke()
复制代码
When you run the script file, it will output a red text and beeps for a second. So the newly created script actually executes the code embedded into the secret NTFS stream "SecretStream".

To attach hidden information to (any) file stored on an NTFS volume, use Add-Content or Set-Content with the -Stream parameter.

To read hidden information from a stream, use Get-Content and again specify the -Stream parameter with the name of the stream used to store the data.

http://powershell.com/cs/blogs/tips/archive/2014/01/27/reading-and-writing-ntfs-streams.aspx
作者: ivor    时间: 2014-2-12 11:31

高深莫测




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2