Protostar stack2

About

Stack2 looks at environment variables, and how they can be set.
This level is at /opt/protostar/bin/stack2

Source code

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
    volatile int modified;
    char buffer[64];
    char *variable;

    variable = getenv("GREENIE");

    if(variable == NULL) {
        errx(1, "please set the GREENIE environment variable\n");
    }

    modified = 0;

    strcpy(buffer, variable);

    if(modified == 0x0d0a0d0a) {
        printf("you have correctly modified the variable\n");
    } else {
        printf("Try again, you got 0x%08x\n", modified);
    }

}


这题首先需要添加一枚环境变量――GREENIE,为什么要这么做呢?依我之见,这算是多提供了一种程序输入的法子,具体的应用倒还没遇过。而添加环境变量的法子也不少,一开始在纠结于环境变量的保存路径,在文本中编辑变量,但是发现这方法貌似不行(没深究,欢迎拍砖),因为Linux用vi编辑文本换行时只用0A,只构造不出关键if中的0D0A!!

后采用命令export搞之,具体命令是(只是长这个模样而已):
$export GREENIE="1234567890 1234567890 1234567890 1234567890 1234567890 12345678901234
>^M
>^M
"
具体输入0D0A的方法是“回车->Ctrl+V->回车" *2

结果如图:


你可能感兴趣的:(Protostar,stack2)