int main(int argc, char *argv[]) { if(strncmp(basename(getenv("_")), "icesh", 6) == 0){ give_shell(); } else { printf("I'm sorry, your free trial has ended.\n"); } return 0; }
To call give_shell() we have to bypass the if statement.
We need the _ environment variable to be _=icesh.
But our zsh shell don't allow us to change: _ is read-only and we can't make it writable.
1 2 3 4
[ctf-578@icectf-shell-2016 /home/demo]$ export \_=icesh zsh: read-only variable: _ [ctf-578@icectf-shell-2016 /home/demo]$ typeset +rx \_=icesh typeset: _: can't change type of a special parameter
_ contain the name of the last command but launching icesh and then ./demo doesn't work in this environment because the last command is ./demo so _=./demo.
As give_shell() will give us a /bin/sh, let's try with it.
Start a /bin/sh.
With /bin/sh, _ contain the last command before last one, so running icesh and then ./demo will work: _=icesh.
So that launch give_shell() and give a /bin/sh enhanced with special gid instead of having I'm sorry, your free trial has ended. printed.
With this empowered shell we can display the flag.txt file: