Exploit database

GH-baa3752fd39e3895667c8fbc596488a3

yoyosh/darkreplica

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-23631

1 source

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.

Repository files3
yoyosh/darkreplicaRevision e9861498c36a

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

dark_replica/lua/structs.py

Python · 6,405 bytes
from enum import Enum
from ctypes import LittleEndianStructure, Union, c_void_p, c_uint8, c_uint16, c_uint32, c_uint, \
    c_int, c_size_t, c_ssize_t, c_char_p, c_ubyte, CFUNCTYPE, POINTER


# Basic type aliases
lu_int32 = c_uint32
lu_byte = c_ubyte
lu_mem = c_size_t

# Define constants
NUM_TAGS = 9
TM_N = 17


class LuaValueType(Enum):
    LUA_TNONE = -1
    LUA_TNIL = 0
    LUA_TBOOLEAN = 1
    LUA_TLIGHTUSERDATA = 2
    LUA_TNUMBER = 3
    LUA_TSTRING = 4
    LUA_TTABLE = 5
    LUA_TFUNCTION = 6
    LUA_TUSERDATA = 7
    LUA_TTHREAD = 8


class TValue(LittleEndianStructure):
    _fields_ = [
        ("value", c_void_p),  # Value
        ("tt", c_int),        # int tt
    ]


class TString_tsv(LittleEndianStructure):
    _fields_ = [
        # CommonHeader fields
        ("next", c_void_p),      # GCObject *next
        ("tt", c_uint8),         # lu_byte tt
        ("marked", c_uint8),     # lu_byte marked
        
        # TString specific fields
        ("reserved", c_uint8),   # lu_byte reserved
        ("hash", c_uint),        # unsigned int hash
        ("len", c_size_t),       # size_t len
    ]


class TString(Union):
    _fields_ = [
        ("dummy", c_void_p),     # L_Umaxalign dummy
        ("tsv", TString_tsv),           # struct with actual fields
    ]


class Table(LittleEndianStructure):
    _fields_ = [
        ("next", c_void_p),           # GCObject *next
        ("tt", c_ubyte),              # lu_byte tt
        ("marked", c_ubyte),          # lu_byte marked
        ("flags", c_ubyte),           # lu_byte flags
        ("readonly", c_int),          # int readonly
        ("lsizenode", c_ubyte),       # lu_byte lsizenode
        ("metatable", c_void_p),      # struct Table *metatable
        ("array", c_void_p),          # TValue *array
        ("node", c_void_p),           # Node *node
        ("lastfree", c_void_p),       # Node *lastfree
        ("gclist", c_void_p),         # GCObject *gclist
        ("sizearray", c_int),         # int sizearray
    ]


lua_CFunction = CFUNCTYPE(c_int, c_void_p)  # Returns int, takes lua_State* (as void*)


class TValue(LittleEndianStructure):
    _fields_ = [
        ("value", c_void_p),  # Value union - treated as void pointer
        ("tt", c_int)
    ]


class CClosure(LittleEndianStructure):
    _fields_ = [
        # CommonHeader fields
        ("next", c_void_p),      # GCObject* next
        ("tt", c_ubyte),         # lu_byte tt
        ("marked", c_ubyte),     # lu_byte marked
        
        # ClosureHeader fields
        ("isC", c_ubyte),        # lu_byte isC
        ("nupvalues", c_ubyte),  # lu_byte nupvalues
        ("gclist", c_void_p),    # GCObject* gclist
        ("env", c_void_p),       # struct Table* env
        
        # CClosure-specific fields
        ("f", lua_CFunction),    # lua_CFunction f
        ("upvalue", TValue * 1)  # TValue upvalue[1] - flexible array member
    ]


# UpVal structure
class UpValUnion(Union):
    class OpenList(LittleEndianStructure):
        _fields_ = [
            ("prev", c_void_p),
            ("next", c_void_p),
        ]
    
    _fields_ = [
        ("value", TValue),
        ("l", OpenList),
    ]

class UpVal(LittleEndianStructure):
    _fields_ = [
        ("next", c_void_p),  # GCObject*
        ("tt", lu_byte),
        ("marked", lu_byte),
        ("v", POINTER(TValue)),
        ("u", UpValUnion),
    ]


# Mbuffer structure
class Mbuffer(LittleEndianStructure):
    _fields_ = [
        ("buffer", c_char_p),
        ("n", c_size_t),
        ("buffsize", c_size_t),
    ]


# stringtable structure
class stringtable(LittleEndianStructure):
    _fields_ = [
        ("hash", c_void_p),  # GCObject**
        ("nuse", lu_int32),
        ("size", c_int),
    ]


# global_State structure
class global_State(LittleEndianStructure):
    _fields_ = [
        ("strt", stringtable),
        ("frealloc", c_void_p),  # lua_Alloc function pointer
        ("ud", c_void_p),
        ("currentwhite", lu_byte),
        ("gcstate", lu_byte),
        ("sweepstrgc", c_int),
        ("rootgc", c_void_p),  # GCObject*
        ("sweepgc", c_void_p),  # GCObject**
        ("gray", c_void_p),  # GCObject*
        ("grayagain", c_void_p),  # GCObject*
        ("weak", c_void_p),  # GCObject*
        ("tmudata", c_void_p),  # GCObject*
        ("buff", Mbuffer),
        ("GCthreshold", lu_mem),
        ("totalbytes", lu_mem),
        ("estimate", lu_mem),
        ("gcdept", lu_mem),
        ("gcpause", c_int),
        ("gcstepmul", c_int),
        ("panic", lua_CFunction),
        ("l_registry", TValue),
        ("mainthread", c_void_p),  # lua_State*
        ("uvhead", UpVal),
        ("mt", c_void_p * NUM_TAGS),  # struct Table*[NUM_TAGS]
        ("tmname", c_void_p * TM_N),  # TString*[TM_N]
    ]


class lua_State(LittleEndianStructure):
    _fields_ = [
        # CommonHeader fields
        ("next", c_void_p),      # GCObject *next
        ("tt", c_uint8),         # lu_byte tt
        ("marked", c_uint8),     # lu_byte marked
        
        # lua_State specific fields
        ("status", c_uint8),     # lu_byte status
        ("top", c_void_p),       # StkId top
        ("base", c_void_p),      # StkId base
        ("l_G", c_void_p),       # global_State *l_G
        ("ci", c_void_p),        # CallInfo *ci
        ("savedpc", c_void_p),   # const Instruction *savedpc
        ("stack_last", c_void_p), # StkId stack_last
        ("stack", c_void_p),     # StkId stack
        ("end_ci", c_void_p),    # CallInfo *end_ci
        ("base_ci", c_void_p),   # CallInfo *base_ci
        ("stacksize", c_int),    # int stacksize
        ("size_ci", c_int),      # int size_ci
        ("nCcalls", c_uint16),   # unsigned short nCcalls
        ("baseCcalls", c_uint16), # unsigned short baseCcalls
        ("hookmask", c_uint8),   # lu_byte hookmask
        ("allowhook", c_uint8),  # lu_byte allowhook
        ("basehookcount", c_int), # int basehookcount
        ("hookcount", c_int),    # int hookcount
        ("hook", c_void_p),      # lua_Hook hook
        ("l_gt", TValue),      # TValue l_gt (treated as pointer)
        ("env", TValue),       # TValue env (treated as pointer)
        ("openupval", c_void_p), # GCObject *openupval
        ("gclist", c_void_p),    # GCObject *gclist
        ("errorJmp", c_void_p),  # struct lua_longjmp *errorJmp
        ("errfunc", c_ssize_t),  # ptrdiff_t errfunc
    ]