Skip to content

Instantly share code, notes, and snippets.

View mahadirz's full-sized avatar
:octocat:
freedom

Mahadir Ahmad mahadirz

:octocat:
freedom
View GitHub Profile
@mahadirz
mahadirz / address-offset.cpp
Created October 28, 2026 05:07
PHP2Shell article: ASLR and function offset demonstration
#include <cstdint>
#include <iostream>
// These names match the toy server. Only their addresses matter here.
void safe_handler() {}
void run_shell() {}
int main() {
auto safe_address = reinterpret_cast<std::intptr_t>(&safe_handler);
auto shell_address = reinterpret_cast<std::intptr_t>(&run_shell);
@mahadirz
mahadirz / oom-bridge.cpp
Last active October 28, 2026 03:35
PHP2Shell article: OOM and two-request pointer bridge
#include <cstdio>
#include <new>
struct Session { int token; };
struct Replacement { int marker; };
alignas(Session) unsigned char slot[sizeof(Session)];
Session *saved = nullptr;
void upload_request() {
@mahadirz
mahadirz / README.md
Last active October 27, 2026 16:15
PHP2Shell-shaped localhost C++ RCE teaching example

Local C++ RCE demonstration

This Gist contains a loopback-only C++ server and Python client for the PHP2Shell article. The client triggers a simulated upload failure, observes a stale-pointer leak, reuses the slot, and makes the server run id. It is a teaching model, not a payload for PHP.

Build with sh build.sh. Run ./server --port 18092 in one terminal and python3 exploit.py --port 18092 in another. Restart the server between runs. For the fixed comparison, use ./server --fixed --port 18093 and python3 exploit.py --port 18093.

@mahadirz
mahadirz / pointer-chain.cpp
Created October 27, 2026 12:22
PHP2Shell article: ordinary variable, pointer, and pointer to pointer
#include <iostream>
int main() {
int a = 32; // An ordinary int holds a value.
int* p = &a; // p holds the address of a.
int** pp = &p; // pp holds the address of p.
std::cout << "a: address=" << &a << " value=" << a << '\n';
std::cout << "p: address=" << &p << " stores=" << p << '\n';
std::cout << "pp: address=" << &pp << " stores=" << pp << '\n';
"""
This snippet is the toy experiment to numerically verify the math
in the Implicit Dynamics of In-Context Learning paper.
The full article is on medium title:Synaptic Plasticity in Transformer Part 1
The code has been converted from the original notebook to a python script.
"""
import torch
import torch.nn.functional as F
import torch
import torch.nn as nn
class MultiHeadAttention(nn.Module):
def __init__(self, dim_in, dim_out, context_length, dropout, num_heads):
super().__init__()
assert dim_out % num_heads == 0, "dim_out must be divisible by num_heads"
self.num_heads = num_heads
@mahadirz
mahadirz / chatgpt.php
Created March 17, 2023 11:50
simple chatgpt prompt using php
<?php
$completion = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Your OpenAI API key
$apiKey = '';
// The message you want to send to OpenAI
$message = $_POST['message'];
foreign
did the gpd4 developer demo live stream
honestly it's kind of hard for me to
believe that this day is here open AI
has been building this technology really
since we started the company but for the
past two years we've been really focused
on delivering gpt4
that started with rebuilding our entire
training stack actually training the
@mahadirz
mahadirz / spark.log
Created January 29, 2022 13:20
MyAWSCredentialsProviderWithUri missing
Py4JJavaError: An error occurred while calling o100.json.
: com.amazon.ws.emr.hadoop.fs.shaded.com.google.inject.ProvisionException: Unable to provision, see the following errors:
1) Error in custom provider, java.lang.NoClassDefFoundError: MyAWSCredentialsProviderWithUri$1
at com.amazon.ws.emr.hadoop.fs.guice.EmrFSBaseModule.provideAmazonS3Lite(EmrFSBaseModule.java:112)
at com.amazon.ws.emr.hadoop.fs.guice.EmrFSBaseModule.provideAmazonS3Lite(EmrFSBaseModule.java:112)
while locating com.amazon.ws.emr.hadoop.fs.s3.lite.AmazonS3Lite
for field at com.amazon.ws.emr.hadoop.fs.s3n.S3NativeFileSystem.s3(S3NativeFileSystem.java:92)
while locating com.amazon.ws.emr.hadoop.fs.s3n.S3NativeFileSystem
while locating org.apache.hadoop.fs.FileSystem annotated with @com.amazon.ws.emr.hadoop.fs.shaded.com.google.inject.name.Named(value=s3n)
@mahadirz
mahadirz / read_mysql_binlog.py
Created January 23, 2022 04:35
mysq-binlog-tutorial
import traceback
import pendulum
import pymysql
from pymysql.protocol import MysqlPacket
from pymysqlreplication.binlogstream import MYSQL_EXPECTED_ERROR_CODES
from pymysqlreplication.constants import *
from pymysqlreplication.event import *
from pymysqlreplication.packet import BinLogPacketWrapper
from pymysqlreplication.row_event import TableMapEvent, UpdateRowsEvent, WriteRowsEvent, DeleteRowsEvent