Skip to content

Instantly share code, notes, and snippets.

View maple3142's full-sized avatar

maple maple3142

  • Taiwan
  • 17:57 (UTC +08:00)
  • X @maple3142
View GitHub Profile
@maple3142
maple3142 / exploit-success.py
Created May 29, 2023 01:08
DEFCON CTF Quals 2023 - IFUCKUP
from sage.all import *
import random
from pwn import *
def well512(state_with_idx):
state, index = state_with_idx
a = state[index]
c = state[(index + 13) & 15]
b = a ^ c ^ (a << 16) ^ (c << 15)
@maple3142
maple3142 / get_mod.py
Created May 8, 2023 05:08
Cryptoverse CTF 2023 - picochip2
from sage.all import crt, lcm, reduce
from Crypto.Util.number import *
import csv
# fmt: off
pico_r = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547]
# fmt: on
def solve_eqs(eqs):
@maple3142
maple3142 / solve.py
Created May 8, 2023 05:07
Cryptoverse CTF 2023 - picochip1
from sage.all import crt, lcm, reduce
from Crypto.Util.number import *
# fmt: off
pico_r = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283]
# fmt: on
def solve_eqs(eqs):
if len(eqs) < 2:
@maple3142
maple3142 / solve.py
Last active May 6, 2023 13:51
WaniCTF 2023 - fusion
from binteger import Bin
import sys
sys.setrecursionlimit(10000)
mask = int("55" * 128, 16) << 1
n = 27827431791848080510562137781647062324705519074578573542080709104213290885384138112622589204213039784586739531100900121818773231746353628701496871262808779177634066307811340728596967443136248066021733132197733950698309054408992256119278475934840426097782450035074949407003770020982281271016621089217842433829236239812065860591373247969334485969558679735740571326071758317172261557282013095697983483074361658192130930535327572516432407351968014347094777815311598324897654188279810868213771660240365442631965923595072542164009330360016248531635617943805455233362064406931834698027641363345541747316319322362708173430359
e = 65537
c = 8879262206679688908793239933227510574535053292824641211921666616686529884723922008336172633568024007865308291986303381324610408548172400458622311631920664068648537784408785822654664172271858326202541370427938566262449889250480881111190046078900257634145087538952254926231933115599220847964
@maple3142
maple3142 / README.md
Last active April 30, 2023 06:07
ångstromCTF 2023 - tau as a service
@maple3142
maple3142 / chall.py
Created April 23, 2023 01:21
ricerca ctf 2023 - rotated secret analysis
import os
from Crypto.Util.number import bytes_to_long, getPrime, isPrime
flag = os.environ.get("FLAG", "fakeflag").encode()
while True:
p = getPrime(1024)
q = (p << 512 | p >> 512) & (2**1024 - 1) # bitwise rotation (cf. https://en.wikipedia.org/wiki/Bitwise_operation#Rotate)
if isPrime(q): break
@maple3142
maple3142 / README.md
Last active September 16, 2024 08:18
poor man's ngrok with cloudflared and mitmproxy

Poor man's ngrok

Prequisites

  • zsh
  • python3
  • tmux
  • cloudflared
  • mitmproxy
@maple3142
maple3142 / README.md
Last active March 20, 2025 12:19
ctf python env
conda create --name ctf sage=10.5 -c conda-forge
pip install web3 pwntools numpy z3-solver httpx fastecdsa pytesseract pyshark flask-unsign flask-unsign[wordlist] binteger websockets pycryptodome ecdsa black gunicorn websockets waitress git-dumper ptrlib gunicorn[gevent] ropper tqdm flask r2pipe PyExifTool python-docx pillow numpy pycurl galois networkx pyshark gradient-free-optimizers bottle playwright
# also try z3-solver==4.11.2.0 which could be faster

# with more ml stuffs:
conda create --name ctf sage=10.2 -c conda-forge scikit-learn pandas pytorch matplotlib torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

# not supported by Python 3.11
# pip install cvc5
@maple3142
maple3142 / poly_sub.sage
Created February 23, 2023 16:52
sage multivariate polynomial variable substitution
def poly_sub(f, x, y):
ret = f.parent().zero()
for c, m in f:
while m % x == 0:
m //= x
c *= y
ret += c * m
return ret
@maple3142
maple3142 / flatter.sage
Last active September 10, 2023 13:18
trying https://github.com/keeganryan/flatter for faster lattice reduction than LLL
from subprocess import check_output, DEVNULL, CalledProcessError
import itertools
import IPython
import time
def to_fplll_format(M):
m, n = M.dimensions()
ret = ""
s = "["