简体   繁体   中英

Powershell read shellcode from file


I have a powershell script which execute the shellcode.
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array
8

The output of above command is

$codes = @(Get-Content -Raw C:\Users\abc\Downloads\code.txt)
$codes.GetType()
[Byte[]] $buf = $codes.ToCharArray()
echo $buf.Length

But when i save the shellcode in text file and executes it, it doesn't execute and buffer length is also different.

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array
39

The Output of above command

 IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array 39

By any chance can i execute the above shellcode from text file and keeping the buffer length same.

If the file consists of 8 bytes, use Get-Content -Encoding Byte :

# Windows PowerShell
$codes = @(Get-Content C:\Users\abc\Downloads\code.txt -Encoding Byte)

# PowerShell 7
$codes = @(Get-Content C:\Users\abc\Downloads\code.txt -AsByteStream)

If the file instead contains the literal string 0xe8,0x3b,0x3d,0x03,0x00,0x3b,0x3d,0x03 , you'll need to split up the list and parse them as numerical values first:

$codes = @(Get-Content -Raw C:\Users\abc\Downloads\code.txt)
$codes = $codes.Trim() -split '(?s)[\s,]+' -as [byte[]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM