repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/tests/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/tests/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/environ.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/environ.py
import os def getenv(key: str) -> str: """Get environment variable and raise an error if it is unset.""" if val := os.getenv(key): return val msg = "ENV variable %s is required!" raise OSError(msg % key) IS_DEV = os.getenv("ENV") == "DEV"
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/utils.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/utils.py
from base64 import urlsafe_b64decode, urlsafe_b64encode def encode(content: bytes | str) -> str: def _encode(): if isinstance(content, str): return urlsafe_b64encode(content.encode()).decode() return urlsafe_b64encode(content).decode() return _encode().replace("=", "") def decod...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/resp.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/resp.py
from __future__ import annotations from fastapi import HTTPException, status PERMISSION_DENIED = HTTPException( status_code=status.HTTP_403_FORBIDDEN, detail="Permission denied.", ) def not_found(model: object) -> HTTPException: return HTTPException( status_code=status.HTTP_404_NOT_FOUND, ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/auth.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/auth.py
from __future__ import annotations import json from datetime import UTC, datetime, timedelta from pathlib import Path from secrets import randbits from typing import Annotated from Crypto.Util.number import getPrime, long_to_bytes from fastapi import Cookie, Depends, HTTPException, Response, status from mvmcryption....
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/app.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/app.py
from fastapi import APIRouter, FastAPI from mvmcryption.db import initialize from mvmcryption.environ import IS_DEV from mvmcryption.routers import auth, crypto, users tags_metadata = [ { "name": "users", "description": "Operations with users.", }, { "name": "crypto", "desc...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/db/users.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/db/users.py
from __future__ import annotations from argon2 import PasswordHasher, exceptions from pydantic import EmailStr, SecretStr from .db import BaseModel, DBModel PH = PasswordHasher() class User(BaseModel): username: str email: EmailStr password: SecretStr @property def is_admin(self): retu...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/db/db.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/db/db.py
from __future__ import annotations import sqlite3 from abc import ABC, abstractmethod from collections.abc import Callable, Iterator, Sequence from contextlib import contextmanager from typing import Annotated, Generic, TypeVar from fastapi import Depends from pydantic import BaseModel as _BaseModel from mvmcryption...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/db/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/db/__init__.py
from __future__ import annotations from mvmcryption.environ import getenv from .db import connect from .users import Users ADMIN_PASSWORD = getenv("ADMIN_PASSWORD") TABLE_QUERY = """ CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, username VARCHAR(50) NOT NULL UNIQUE, email VARCHAR(100) NOT N...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/routers/users.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/routers/users.py
from typing import Annotated, Literal from fastapi import APIRouter, Depends, HTTPException, Response, status from pydantic import BaseModel, EmailStr from mvmcryption.auth import AuthorizedUser from mvmcryption.db import Users from mvmcryption.resp import PERMISSION_DENIED, not_found from mvmcryption.routers.auth im...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/routers/crypto.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/routers/crypto.py
from datetime import datetime from random import getrandbits from Crypto.Util.number import long_to_bytes from fastapi import APIRouter from pydantic import BaseModel, validator from mvmcryption.auth import ( AuthorizedUser, GlobalECDSA, GlobalRSA, GlobalSCBCCipher, ) from mvmcryption.environ import g...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/routers/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/routers/__init__.py
from .auth import auth_router as auth from .crypto import crypto_router as crypto from .users import users_router as users __all__ = [ "auth", "crypto", "users", ]
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/routers/auth.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/routers/auth.py
from datetime import UTC, datetime from typing import Annotated from fastapi import APIRouter, Cookie, Depends, HTTPException, Response, status from pydantic import BaseModel, EmailStr, Field from mvmcryption.auth import ( SJWT_TTL, AuthorizedUser, create_sjwt, decode_sjwt, global_sjwt, ) from mvm...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/ecdsa.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/ecdsa.py
"""Cryptography stuff.""" from dataclasses import dataclass from hashlib import sha256 from pathlib import Path from random import getrandbits from secrets import randbelow from Crypto.Util.number import bytes_to_long, long_to_bytes from fastecdsa.curve import P256, Curve from fastecdsa.ecdsa import verify from faste...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/jwt.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/jwt.py
from dataclasses import dataclass from json import dumps, loads from mvmcryption.utils import decode as b64decode from mvmcryption.utils import encode as b64encode from .ecdsa import ECDSA, decode_signature, encode_signature # SJWT -> Scuffed JSON Web Token; just some extra pain class SJWTError(ValueError): ""...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/rsa.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/rsa.py
from dataclasses import dataclass from Crypto.Hash import SHA256 HASH_LEN = SHA256.digest_size assert HASH_LEN == 32 HASH_BITS = SHA256.digest_size * 8 assert HASH_BITS == 256 @dataclass class PrivKey: p: int q: int e: int @property def phi(self): return (self.p - 1) * (self.q - 1) ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/cipher.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/cipher.py
from dataclasses import dataclass from random import getrandbits from Crypto.Cipher import AES from Crypto.Util.number import long_to_bytes from Crypto.Util.Padding import pad, unpad from pwn import xor from mvmcryption.crypto.rsa import RSA from mvmcryption.utils import chunk BLOCK_SIZE = 16 @dataclass class SCBC...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-2/api/mvmcryption/crypto/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/tests/test_ecdsa.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/tests/test_ecdsa.py
import pytest from mvmcryption.crypto.ecdsa import ECDSA, decode_signature, encode_signature @pytest.mark.parametrize("msg", [b"helo", b'{"get pwned": 1337}']) @pytest.mark.parametrize("d", [1337, 895]) def test_ecdsa(msg: bytes, d: int): ecdsa = ECDSA(d) sig = ecdsa.sign(msg) assert ecdsa.verify(sig, ms...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/tests/test_cipher.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/tests/test_cipher.py
from random import getrandbits, seed import pytest from Crypto.Util.number import long_to_bytes from mvmcryption.crypto.cipher import XSCBCCipher from mvmcryption.crypto.rsa import RSA @pytest.mark.parametrize("msg", [b"helo", b'{"get pwned": 1337}']) @pytest.mark.parametrize("d", [1337, 895]) def test_xscbccipher(m...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/tests/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/tests/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/environ.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/environ.py
import os def getenv(key: str) -> str: """Get environment variable and raise an error if it is unset.""" if val := os.getenv(key): return val msg = "ENV variable %s is required!" raise OSError(msg % key) IS_DEV = os.getenv("ENV") == "DEV"
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/utils.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/utils.py
from base64 import urlsafe_b64decode, urlsafe_b64encode def encode(content: bytes | str) -> str: def _encode(): if isinstance(content, str): return urlsafe_b64encode(content.encode()).decode() return urlsafe_b64encode(content).decode() return _encode().replace("=", "") def decod...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/resp.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/resp.py
from __future__ import annotations from fastapi import HTTPException, status PERMISSION_DENIED = HTTPException( status_code=status.HTTP_403_FORBIDDEN, detail="Permission denied.", ) def not_found(model: object) -> HTTPException: return HTTPException( status_code=status.HTTP_404_NOT_FOUND, ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/auth.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/auth.py
from __future__ import annotations import json from datetime import UTC, datetime, timedelta from pathlib import Path from secrets import randbits from typing import Annotated from Crypto.Util.number import long_to_bytes from fastapi import Cookie, Depends, HTTPException, Response, status from mvmcryption.crypto.cip...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/app.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/app.py
from fastapi import APIRouter, FastAPI from mvmcryption.db import initialize from mvmcryption.environ import IS_DEV from mvmcryption.routers import auth, crypto, users tags_metadata = [ { "name": "users", "description": "Operations with users.", }, { "name": "crypto", "desc...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/db/users.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/db/users.py
from __future__ import annotations from argon2 import PasswordHasher, exceptions from pydantic import EmailStr, SecretStr from .db import BaseModel, DBModel PH = PasswordHasher() class User(BaseModel): username: str email: EmailStr password: SecretStr @property def is_admin(self): retu...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/db/db.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/db/db.py
from __future__ import annotations import sqlite3 from abc import ABC, abstractmethod from collections.abc import Callable, Iterator, Sequence from contextlib import contextmanager from typing import Annotated, Generic, TypeVar from fastapi import Depends from pydantic import BaseModel as _BaseModel from mvmcryption...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/db/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/db/__init__.py
from __future__ import annotations from mvmcryption.environ import getenv from .db import connect from .users import Users ADMIN_PASSWORD = getenv("ADMIN_PASSWORD") TABLE_QUERY = """ CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, username VARCHAR(50) NOT NULL UNIQUE, email VARCHAR(100) NOT N...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/routers/users.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/routers/users.py
from typing import Annotated, Literal from fastapi import APIRouter, Depends, HTTPException, Response, status from pydantic import BaseModel, EmailStr from mvmcryption.auth import AuthorizedUser from mvmcryption.db import Users from mvmcryption.resp import PERMISSION_DENIED, not_found from mvmcryption.routers.auth im...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/routers/crypto.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/routers/crypto.py
from datetime import datetime from fastapi import APIRouter from pydantic import BaseModel, validator from mvmcryption.auth import ( AuthorizedUser, GlobalECDSA, GlobalRSA, GlobalXSCBCCipher, ) from mvmcryption.environ import getenv from mvmcryption.utils import decode, encode FLAG = getenv("FLAG").e...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/routers/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/routers/__init__.py
from .auth import auth_router as auth from .crypto import crypto_router as crypto from .users import users_router as users __all__ = [ "auth", "crypto", "users", ]
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/routers/auth.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/routers/auth.py
from datetime import UTC, datetime from typing import Annotated from fastapi import APIRouter, Cookie, Depends, HTTPException, Response, status from pydantic import BaseModel, EmailStr, Field from mvmcryption.auth import ( SJWT_TTL, AuthorizedUser, create_sjwt, decode_sjwt, global_sjwt, ) from mvm...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/ecdsa.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/ecdsa.py
"""Cryptography stuff.""" from dataclasses import dataclass from hashlib import sha256 from pathlib import Path from random import getrandbits from secrets import randbelow from Crypto.Util.number import bytes_to_long, long_to_bytes from fastecdsa.curve import P256, Curve from fastecdsa.ecdsa import verify from faste...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/jwt.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/jwt.py
from dataclasses import dataclass from json import dumps, loads from mvmcryption.utils import decode as b64decode from mvmcryption.utils import encode as b64encode from .ecdsa import ECDSA, decode_signature, encode_signature # SJWT -> Scuffed JSON Web Token; just some extra pain class SJWTError(ValueError): ""...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/rsa.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/rsa.py
from dataclasses import dataclass from secrets import token_bytes from Crypto.Hash import SHA256 from Crypto.Signature.pss import MGF1 from Crypto.Util.number import getPrime, isPrime HASH_LEN = SHA256.digest_size assert HASH_LEN == 32 HASH_BITS = SHA256.digest_size * 8 assert HASH_BITS == 256 def fast_prime(e: int...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/cipher.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/cipher.py
from dataclasses import dataclass from random import getrandbits from Crypto.Cipher import AES from Crypto.Util.number import long_to_bytes from Crypto.Util.Padding import pad, unpad from pwn import xor from mvmcryption.crypto.rsa import RSA from mvmcryption.utils import chunk BLOCK_SIZE = 16 @dataclass class SCBC...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-3/api/mvmcryption/crypto/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/tests/test_ecdsa.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/tests/test_ecdsa.py
import pytest from mvmcryption.crypto.ecdsa import ECDSA, decode_signature, encode_signature @pytest.mark.parametrize("msg", [b"helo", b'{"get pwned": 1337}']) @pytest.mark.parametrize("d", [1337, 895]) def test_ecdsa(msg: bytes, d: int): ecdsa = ECDSA(d) sig = ecdsa.sign(msg) assert ecdsa.verify(sig, ms...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/tests/test_cipher.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/tests/test_cipher.py
from random import getrandbits import pytest from Crypto.Util.number import long_to_bytes from mvmcryption.crypto.cipher import SCBCCipher @pytest.mark.parametrize("msg", [b"helo", b'{"get pwned": 1337}']) @pytest.mark.parametrize("d", [1337, 895]) def test_scbccipher(msg: bytes, d: int): key = long_to_bytes(d, ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/tests/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/tests/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/environ.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/environ.py
import os def getenv(key: str) -> str: """Get environment variable and raise an error if it is unset.""" if val := os.getenv(key): return val msg = "ENV variable %s is required!" raise OSError(msg % key) IS_DEV = os.getenv("ENV") == "DEV"
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/utils.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/utils.py
from base64 import urlsafe_b64decode, urlsafe_b64encode def encode(content: bytes | str) -> str: def _encode(): if isinstance(content, str): return urlsafe_b64encode(content.encode()).decode() return urlsafe_b64encode(content).decode() return _encode().replace("=", "") def decod...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/resp.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/resp.py
from __future__ import annotations from fastapi import HTTPException, status PERMISSION_DENIED = HTTPException( status_code=status.HTTP_403_FORBIDDEN, detail="Permission denied.", ) def not_found(model: object) -> HTTPException: return HTTPException( status_code=status.HTTP_404_NOT_FOUND, ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/auth.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/auth.py
from __future__ import annotations import json from datetime import UTC, datetime, timedelta from pathlib import Path from secrets import randbits from typing import Annotated from Crypto.Util.number import getPrime, long_to_bytes from fastapi import Cookie, Depends, HTTPException, Response, status from mvmcryption....
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/app.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/app.py
from fastapi import APIRouter, FastAPI from mvmcryption.db import initialize from mvmcryption.environ import IS_DEV from mvmcryption.routers import auth, crypto, users tags_metadata = [ { "name": "users", "description": "Operations with users.", }, { "name": "crypto", "desc...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/db/users.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/db/users.py
from __future__ import annotations from argon2 import PasswordHasher, exceptions from pydantic import EmailStr, SecretStr from .db import BaseModel, DBModel PH = PasswordHasher() class User(BaseModel): username: str email: EmailStr password: SecretStr @property def is_admin(self): retu...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/db/db.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/db/db.py
from __future__ import annotations import sqlite3 from abc import ABC, abstractmethod from collections.abc import Callable, Iterator, Sequence from contextlib import contextmanager from typing import Annotated, Generic, TypeVar from fastapi import Depends from pydantic import BaseModel as _BaseModel from mvmcryption...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/db/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/db/__init__.py
from __future__ import annotations from mvmcryption.environ import getenv from .db import connect from .users import Users ADMIN_PASSWORD = getenv("ADMIN_PASSWORD") TABLE_QUERY = """ CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, username VARCHAR(50) NOT NULL UNIQUE, email VARCHAR(100) NOT N...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/routers/users.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/routers/users.py
from typing import Annotated, Literal from fastapi import APIRouter, Depends, HTTPException, Response, status from pydantic import BaseModel, EmailStr from mvmcryption.auth import AuthorizedUser from mvmcryption.db import Users from mvmcryption.resp import PERMISSION_DENIED, not_found from mvmcryption.routers.auth im...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/routers/crypto.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/routers/crypto.py
from random import getrandbits from Crypto.Util.number import long_to_bytes from fastapi import APIRouter from pydantic import BaseModel, validator from mvmcryption.auth import ( AdminUser, AuthorizedUser, GlobalECDSA, GlobalSCBCCipher, ) from mvmcryption.environ import getenv from mvmcryption.utils i...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/routers/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/routers/__init__.py
from .auth import auth_router as auth from .crypto import crypto_router as crypto from .users import users_router as users __all__ = [ "auth", "crypto", "users", ]
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/routers/auth.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/routers/auth.py
from datetime import UTC, datetime from typing import Annotated from fastapi import APIRouter, Cookie, Depends, HTTPException, Response, status from pydantic import BaseModel, EmailStr, Field from mvmcryption.auth import ( SJWT_TTL, AuthorizedUser, create_sjwt, decode_sjwt, global_sjwt, ) from mvm...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/crypto/ecdsa.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/crypto/ecdsa.py
"""Cryptography stuff.""" from dataclasses import dataclass from hashlib import sha256 from pathlib import Path from random import getrandbits from secrets import randbelow from Crypto.Util.number import bytes_to_long, long_to_bytes from fastecdsa.curve import P256, Curve from fastecdsa.ecdsa import verify from faste...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/crypto/jwt.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/crypto/jwt.py
from dataclasses import dataclass from json import dumps, loads from mvmcryption.utils import decode as b64decode from mvmcryption.utils import encode as b64encode from .ecdsa import ECDSA, decode_signature, encode_signature # SJWT -> Scuffed JSON Web Token; just some extra pain class SJWTError(ValueError): ""...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/crypto/cipher.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/crypto/cipher.py
from dataclasses import dataclass from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad from pwn import xor from mvmcryption.utils import chunk BLOCK_SIZE = 16 @dataclass class SCBCCipher: """ Scuffed CBC Cipher. If you're wondering why we aren't using CBC directly, this is part of ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/crypto/__init__.py
ctfs/x3ctf/2025/crypto/much-vulnerable-machine-1/api/mvmcryption/crypto/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/curved-mvm/server.py
ctfs/x3ctf/2025/crypto/curved-mvm/server.py
from sage.all import * import os from json import dumps from secrets import randbits from Crypto.Util.number import bytes_to_long from hashlib import sha1 FLAG = os.getenv("FLAG", "MVM{f4ke_fl4g}") # a wonderful curve p = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF a = 0xFFFFFFFF00000001000000...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/x3ctf/2025/crypto/curved-mvm/fast.py
ctfs/x3ctf/2025/crypto/curved-mvm/fast.py
import os from json import dumps from secrets import randbits from hashlib import sha1 from fastecdsa.curve import P256 from fastecdsa.point import Point n = P256.q FLAG = os.getenv("FLAG", "MVM{f4ke_fl4g}") SECRET_KEY = int.from_bytes(os.urandom(69420)) % n Q = SECRET_KEY * P256.G FUNNY_CREDITS_FOR_FREE_TRIAL = 2...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Mapna/2024/pwn/U2S/stuff/run.py
ctfs/Mapna/2024/pwn/U2S/stuff/run.py
#!/usr/bin/env python3 import tempfile import pathlib import os import re import json import time import signal import re if not os.path.exists('/tmp/ips.json'): f = open('/tmp/ips.json','w') f.write('{}') f.close() ipFile = open('/tmp/ips.json','r+') peerIp = os.environ['SOCAT_PEERADDR'] ips = {} ips = json.load...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Mapna/2024/pwn/Protector/generate_directory_tree.py
ctfs/Mapna/2024/pwn/Protector/generate_directory_tree.py
import os import random import string flag = "MAPNA{placeholder_for_flag}" MIN_NAME_LENGTH = 8 MAX_NAME_LENGTH = 16 FILES_COUNT = 0x100 def get_random_name(): n = random.randint(MIN_NAME_LENGTH, MAX_NAME_LENGTH) return "".join(random.choice(string.ascii_letters + string.digits) for i in range(n)) def generate_fil...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Mapna/2024/crypto/What_next_II/what_next_ii.py
ctfs/Mapna/2024/crypto/What_next_II/what_next_ii.py
#!/usr/bin/env python3 from random import * from Crypto.Util.number import * from flag import flag def encrypt(msg, KEY): m = bytes_to_long(msg) c = KEY ^ m return c n = 80 TMP = [getrandbits(256) * _ ** 2 for _ in range(n)] KEY = sum([getrandbits(256 >> _) ** 2 for _ in range(8)]) enc = encrypt(flag, KEY) pri...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Mapna/2024/crypto/Be_Fast/be_fast.py
ctfs/Mapna/2024/crypto/Be_Fast/be_fast.py
#!/usr/bin/env python3 from random import * from binascii import * from Crypto.Cipher import DES from signal import * import sys, os from flag import flag def die(*args): pr(*args) quit() def pr(*args): s = " ".join(map(str, args)) sys.stdout.write(s + "\n") sys.stdout.flush() def sc(): return sys.stdin.buffe...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Mapna/2024/crypto/Shibs/shibs.py
ctfs/Mapna/2024/crypto/Shibs/shibs.py
#!/usr/bin/env python3 from Crypto.Util.number import * from flag import flag def shift(s, B): assert s < len(B) return B[s:] + B[:s] def gen_key(nbit): while True: p = getPrime(nbit) B = bin(p)[2:] for s in range(1, nbit): q = int(shift(s, B), 2) if isPrime(q): n = p * q return n, p, s nbit ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Mapna/2024/crypto/What_next/what_next.py
ctfs/Mapna/2024/crypto/What_next/what_next.py
#!/usr/bin/env python3 from random import * from Crypto.Util.number import * from flag import flag def encrypt(msg, KEY): m = bytes_to_long(msg) c = KEY ^ m return c n = 80 TMP = [getrandbits(256) * _ ** 2 for _ in range(n)] KEY = sum([getrandbits(256 >> _) for _ in range(8)]) enc = encrypt(flag, KEY) print(f'...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Mapna/2024/web/Novel_reader/stuff/main.py
ctfs/Mapna/2024/web/Novel_reader/stuff/main.py
from flask import * from urllib.parse import unquote import os def readFile(path): f = open(path,'r') buf = f.read(0x1000) f.close() return buf app = Flask(__name__,static_folder='./static') app.secret_key = 'REDACTED' indexFile = readFile('index.html') @app.before_request def init_session(): if(...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2018/Quals/7amebox1/_7amebox.py
ctfs/Codegate/2018/Quals/7amebox1/_7amebox.py
#!/usr/bin/python import random import signal import sys PERM_MAPPED = 0b1000 PERM_READ = 0b0100 PERM_WRITE = 0b0010 PERM_EXEC = 0b0001 TYPE_R = 0 TYPE_I = 1 FLAG_NF = 0b0010 FLAG_ZF = 0b0001 CODE_DEFAULT_BASE = 0x00000 STACK_DEFAULT_BASE = 0xf4000 class Stdin: def read(self, size): res = '' ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2018/Quals/7amebox1/vm_name.py
ctfs/Codegate/2018/Quals/7amebox1/vm_name.py
#!/usr/bin/python import string import random import _7amebox from hashlib import sha1 # proof of work print """ ------------------------------------------------------------------------------------ if not (answer.startswith(prefix) and sha1(answer).hexdigest().endswith('000000')): print 'nope' exit(-1) ------...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2018/Quals/7amebox2/vm_adventure.py
ctfs/Codegate/2018/Quals/7amebox2/vm_adventure.py
#!/usr/bin/python import string import random import _7amebox from hashlib import sha1 # proof of work print """ ------------------------------------------------------------------------------------ if not (answer.startswith(prefix) and sha1(answer).hexdigest().endswith('000000')): print 'nope' exit(-1) ------...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2018/Quals/7amebox2/_7amebox.py
ctfs/Codegate/2018/Quals/7amebox2/_7amebox.py
#!/usr/bin/python import random import signal import sys PERM_MAPPED = 0b1000 PERM_READ = 0b0100 PERM_WRITE = 0b0010 PERM_EXEC = 0b0001 TYPE_R = 0 TYPE_I = 1 FLAG_NF = 0b0010 FLAG_ZF = 0b0001 CODE_DEFAULT_BASE = 0x00000 STACK_DEFAULT_BASE = 0xf4000 class Stdin: def read(self, size): res = '' ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/pwn/CST/wrapper.py
ctfs/Codegate/2023/Quals/pwn/CST/wrapper.py
import subprocess import tempfile import base64 import os code = input('Enter Your base64 > ') try: code = base64.b64decode(code) except: print('base64 error') exit(1) if b'#' in code: print('error') exit(1) _, filename = tempfile.mkstemp(prefix='ctf-') f = open(filename, 'wb') f.write(code) f...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/pwn/pcpu/precheck.py
ctfs/Codegate/2023/Quals/pwn/pcpu/precheck.py
from pwn import * import sys import os f = open(sys.argv[1], 'rb') size = int(f.readline()) ops = [] for i in range(size): ops.append(p32(int(f.readline()) & 0xffffffff)) f.close() regs = { '0': {'size': 0, 'data': 0}, '1': {'size': 0, 'data': 0}, '2': {'size': 0, 'data': 0}, '3': {'size': 0, 'd...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/crypto/secure_primeGenerator/client_example.py
ctfs/Codegate/2023/Quals/crypto/secure_primeGenerator/client_example.py
from Crypto.Util.number import * from hashlib import sha256 from pwn import * from itertools import product import random def get_additive_shares(x, n, mod): shares = [0] * n shares[n-1] = x for i in range(n-1): shares[i] = random.randrange(mod) shares[n-1] = (shares[n-1] - shares[i]) % mod...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/crypto/secure_primeGenerator/prob.py
ctfs/Codegate/2023/Quals/crypto/secure_primeGenerator/prob.py
from Crypto.Util.number import * from hashlib import sha256 import os import signal BITS = 512 def POW(): b = os.urandom(32) print(f"b = ??????{b.hex()[6:]}") print(f"SHA256(b) = {sha256(b).hexdigest()}") prefix = input("prefix > ") b_ = bytes.fromhex(prefix + b.hex()[6:]) return sha256(b_).di...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/crypto/My_File_Encryptor/remote.py
ctfs/Codegate/2023/Quals/crypto/My_File_Encryptor/remote.py
#!/usr/bin/env python3 from file_crypto import FileCipher, random_index, index_from_bytes from file_crypto import LOCAL_NONCE import base64 if __name__ == "__main__": # Read data mode = input("mode? ").strip() nonce = base64.b64decode(input("nonce? ").strip()) index_bytes = base64.b64decode(input("ind...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/crypto/My_File_Encryptor/local.py
ctfs/Codegate/2023/Quals/crypto/My_File_Encryptor/local.py
#!/usr/bin/env python3 from file_crypto import FileCipher, random_index, index_to_bytes, index_from_bytes from file_crypto import LOCAL_NONCE, BLOCK_SIZE, INDEX_SIZE import sys if __name__ == "__main__": assert len(sys.argv) == 3 cipher = FileCipher() with open(sys.argv[2], "rb") as f: data = f.r...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/crypto/My_File_Encryptor/file_crypto.py
ctfs/Codegate/2023/Quals/crypto/My_File_Encryptor/file_crypto.py
#!/usr/bin/env python3 from __future__ import annotations from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad import random import struct BLOCK_SIZE = 16 INDEX_SIZE = 20 KEY_SIZE = 16 LOCAL_NONCE = bytes(range(BLOCK_SIZE)) def random_index() -> list[int]: return [random.randint(0, 64) for...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/crypto/anti_Kerckhoffs/prob.py
ctfs/Codegate/2023/Quals/crypto/anti_Kerckhoffs/prob.py
import math import os import hashlib import signal import secrets QUERY_LIMIT = 77777 MOD = 17 m = 20 def quadratic_eval(coeffs, x): return (coeffs[2] * x ** 2 + coeffs[1] * x + coeffs[0]) % MOD def get_random_quadratic(): c2 = secrets.randbelow(MOD - 1) + 1 c1 = secrets.randbelow(MOD) c0 = secrets.r...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/web/CODEGATE_Music_Player/worker/app/worker.py
ctfs/Codegate/2023/Quals/web/CODEGATE_Music_Player/worker/app/worker.py
#!/usr/bin/python3 -u #-*- coding: utf-8 -*- # Developer: stypr (https://harold.kim/) # Target is at http://nginx/ import os import asyncio import time import redis import requests from pyppeteer import launch redis = redis.Redis('redis') redis.select(1) browser = None browser_option = { 'executablePath': '/usr/b...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/web/Calculator/verify_pow.py
ctfs/Codegate/2023/Quals/web/Calculator/verify_pow.py
#!/usr/bin/env python3 import secrets import hashlib from time import time import sys class NcPowser: def __init__(self, difficulty=22, prefix_length=16): self.difficulty = difficulty self.prefix_length = prefix_length def get_challenge(self): return secrets.token_urlsafe(self.prefix_l...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2023/Quals/web/Calculator/gen_pow.py
ctfs/Codegate/2023/Quals/web/Calculator/gen_pow.py
#!/usr/bin/env python3 import secrets import hashlib from time import time class NcPowser: def __init__(self, difficulty=28, prefix_length=22): self.difficulty = difficulty self.prefix_length = prefix_length def get_challenge(self): return secrets.token_urlsafe(self.prefix_length)[:sel...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/Happy_S-box/chal.py
ctfs/Codegate/2022/Quals/crypto/Happy_S-box/chal.py
#!/usr/bin/python3 import os import random class LFSR: rand = random.Random("Codegate2022") Sbox = [ [0] * 64 + [1] * 64 for _ in range(512 - 6) ] for i in range(len(Sbox)): rand.shuffle(Sbox[i]) def __init__(self, seed): self.state = seed for _ in range(1024): self...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/DarkArts/chal.py
ctfs/Codegate/2022/Quals/crypto/DarkArts/chal.py
import os import hashlib import signal signal.alarm(300) def inner_product(u, v): assert len(u) == len(v) res = 0 for a, b in zip(u, v): res += a * b return res def guess_mode(G): while True: idx = int(input()) if idx == 0: x = int(input()) print(...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/PrimeGenerator/prime_generator.py
ctfs/Codegate/2022/Quals/crypto/PrimeGenerator/prime_generator.py
#!/usr/bin/python3 from Crypto.Util.number import * import os BITS = 512 UPPER_BITS = 296 LOWER_BITS = BITS - UPPER_BITS UPPER = bytes_to_long(os.urandom(UPPER_BITS // 8)) << LOWER_BITS FLAG = b'codegate2022{this_is_a_sample_flag}' def menu1(): while True: lower = bytes_to_long(os.urandom(LOWER_BITS // 8...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/manage.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/manage.py
#!/usr/bin/env python """Django's command-line utility for administrative tasks.""" import os import sys def main(): """Run administrative tasks.""" os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'nft_web.settings') try: from django.core.management import execute_from_command_line except Impo...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/asgi.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/asgi.py
""" ASGI config for nft_web project. It exposes the ASGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ """ import os from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTI...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/settings.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/settings.py
""" Django settings for nft_web project. Generated by 'django-admin startproject' using Django 3.2.1. For more information on this file, see https://docs.djangoproject.com/en/3.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """ from pathlib...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/__init__.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/wsgi.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/wsgi.py
""" WSGI config for nft_web project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ """ import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTI...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/urls.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/nft_web/urls.py
"""nft_web URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.2/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/views.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/views.py
from django.shortcuts import render from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.template import loader from django.core.validators import URLValidator, validate_ipv4_address from .models import User from .apps import AccountConfig from .eth import Account, Contract, web3 import ipadd...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/eth.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/eth.py
from typing import Any, Dict, List, Optional, Union import rlp from brownie.exceptions import VirtualMachineError from eth_typing import ChecksumAddress from eth_utils import keccak, to_checksum_address from hexbytes import HexBytes from web3 import Web3 from web3.contract import ContractFunctions class Account: ...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/models.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/models.py
from django.db import models # Create your models here. class User(models.Model): user_id = models.CharField(max_length=128) user_pw = models.CharField(max_length=128) token = models.CharField(max_length=512) token_key = models.CharField(max_length=512) is_cached = models.BooleanField(default=False...
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/__init__.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/__init__.py
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/tests.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/tests.py
from django.test import TestCase # Create your tests here.
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/apps.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/apps.py
from django.apps import AppConfig from .eth import Account, Contract, web3 import os class AccountConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'account' nft_addr = open(os.path.join(os.getcwd(), 'contract_addr.txt'), 'rb').read().strip().decode('utf-8')
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false
sajjadium/ctf-archives
https://github.com/sajjadium/ctf-archives/blob/129a3a9fe604443211fa4d493a49630c30689df7/ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/urls.py
ctfs/Codegate/2022/Quals/crypto/nft/nft_web/account/urls.py
from django.urls import path from . import views urlpatterns = [ path('', views.index, name='index'), path('login', views.login, name='login'), path('regist', views.regist, name='regist'), path('logout', views.logout, name='logout'), path('<str:user_id>/nfts/', views.nfts, name='nfts'), ]
python
MIT
129a3a9fe604443211fa4d493a49630c30689df7
2026-01-05T01:34:13.869332Z
false