-1

I'm doing a simple exercise where copy a base64 encoded cookie value, and then make a few changes and then re-encode, and then use the result to log into a site as admin.

I have the following encoded string:

Tzo0OiJVc2VyIjoyOntzOjg6InVzZXJuYW1lIjtzOjU6ImRhZHNhIjtzOjc6ImlzQWRtaW4iO2I6MDt9 

I decode it like so:

$ echo Tzo0OiJVc2VyIjoyOntzOjg6InVzZXJuYW1lIjtzOjU6ImRhZHNhIjtzOjc6ImlzQWRtaW4iO2I6MDt9 | base64 --decode                       1 ⨯
O:4:"User":2:{s:8:"username";s:5:"dadsa";s:7:"isAdmin";b:0;} 

I then make a small change in order to be able to log in as admin:

O:4:"User":2:{s:8:"username";s:5:"dadsa";s:7:"isAdmin";b:1;} 

And them attempt to encode it again:

$ echo O:4:"User":2:{s:8:"username";s:5:"dadsa";s:7:"isAdmin";b:0;} | base64                                                    1 ⨯
zsh: parse error near `}'

Which gives me a parsing error. I did this the other day, where this worked perfectly .

Why am i not able to encode this string?

  • This time, I don't think that one answers it, as it's more about values expanded from variables (etc), and doesn't seem to mention semicolons at all. – ilkkachu Sep 11 '21 at 13:08
  • 1
    Semicolon is a special character, quoting would have solved it. – muru Sep 12 '21 at 03:05

1 Answers1

3
echo O:4:"User":2:{s:8:"username";s:5:"dadsa";s:7:"isAdmin";b:0;}
                                 ^           ^             ^   ^

The unquoted semicolons there work as command separators. Same as running echo foo; ls -l runs both echo and ls and not just echo. The } is a shell keyword, similarly to if, then or fi, and it's not in a syntactically correct place there, hence the error. (zsh doesn't accept even echo }, so there, it might be parsed as an operator, too.)

If you remove the }, you'll see "command not found" errors for s:5:dadsa etc.

You probably meant to quote the string:

echo 'O:4:"User":2:{s:8:"username";s:5:"dadsa";s:7:"isAdmin";b:0;}'

There's some lists of the shells' (plural) special characters in some Q&As here, e.g.
What characters are required to be escaped in command line arguments? Also see How to use a special character as a normal one in Unix shells? and What is the difference between the "...", '...', $'...', and $"..." quotes in the shell?

ilkkachu
  • 138,973