Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View moyix's full-sized avatar

Brendan Dolan-Gavitt moyix

View GitHub Profile
@moyix
moyix / README.md
Created March 8, 2024 22:45
Claude 3 writes a fuzzer for VRML files

C++ files are are from this GitHub repository, with a small modification by me to allow the parser to accept a filename on the command line:

https://github.com/alepapadop/vrml

genvrml_v*.py written by Claude 3 Opus.

The conversation was:

Initial Prompt

@moyix
moyix / gengif_spec.py
Created March 8, 2024 20:57
Claude's random GIF generator, based only on the GIF89a spec
from typing import BinaryIO
import random
import struct
def generate_random_input(out: BinaryIO):
# Generate Header
out.write(b'GIF89a') # GIF signature and version
# Generate Logical Screen Descriptor
screen_width = random.randint(1, 65535)
@moyix
moyix / gengif_nocode.py
Created March 8, 2024 16:13
Claude's random GIF generator, without seeing the parser code
from typing import BinaryIO
import random
import struct
def generate_random_input(out: BinaryIO):
# Generate a random width and height (between 1 and 1000)
width = random.randint(1, 1000)
height = random.randint(1, 1000)
# Write GIF header
@moyix
moyix / Makefile
Created March 8, 2024 05:26
Claude 3 writes a fuzzer
all: gifread gifread.asan gifread.ubsan gifread.coverage
gifread: gifdec.c gifread.c gifdec.h
$(CC) $(CFLAGS) -o $@ gifdec.c gifread.c $(LDFLAGS)
gifread.asan: gifdec.c gifread.c gifdec.h
$(CC) $(CFLAGS) -g -fsanitize=address -o $@ gifdec.c gifread.c $(LDFLAGS)
gifread.ubsan: gifdec.c gifread.c gifdec.h
$(CC) $(CFLAGS) -g -fsanitize=undefined -o $@ gifdec.c gifread.c $(LDFLAGS)
@moyix
moyix / DecompileToJson.java
Created January 27, 2024 06:16
Ghidra scripts to produce JSON files with decompilation / disassembly for each function in an binary
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ghidra.app.script.GhidraScript;
import ghidra.app.decompiler.DecompInterface;
Given the following program:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFERSIZE 200
#define TRUE 1
#define FALSE 0
@moyix
moyix / gen_chat_html.py
Created November 15, 2023 23:18
Render LM-Studio Chat as HTML
import json
import argparse
import html
import os
from datetime import datetime
def generate_html(json_file, html_file="chat.html", metadata=None, date=None):
with open(json_file, 'r') as file:
data = json.load(file)
@moyix
moyix / basicbof.c
Created November 8, 2023 02:52
Buffer overflow with two ROP chains
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// Build:
// gcc -gdwarf-4 -fcf-protection=none -no-pie -fno-stack-protector basicbof.c -o basicbof
// To give us a pop rdi gadget
void dosomething() {
int x = 0xc35f;
@moyix
moyix / stream_generation.py
Created September 6, 2023 22:06
StoppingCriteria abused to print tokens to stdout as they're generated
import sys
import torch
from transformers import StoppingCriteria, StoppingCriteriaList
from transformers import AutoTokenizer, AutoModelForCausalLM
class StreamPrinter(StoppingCriteria):
def __init__(self):
StoppingCriteria.__init__(self)
self.pos = 0
def __call__(self, input_ids, scores):
@moyix
moyix / .env.local
Created August 19, 2023 22:40
Setup for locally hosted LLM chat using chat-ui and TGI with WizardLM-70B
MONGODB_URL=mongodb://localhost:27017
HF_ACCESS_TOKEN=<REDACTED>
# 'name', 'userMessageToken', 'assistantMessageToken' are required
MODELS=`[
{
"endpoints": [{"url": "http://localhost:8081"}],
"name": "WizardLM/WizardLM-70B-V1.0",
"description": "WizardLM: Empowering Large Pre-Trained Language Models to Follow Complex Instructions",
"websiteUrl": "https://huggingface.co/WizardLM/WizardLM-70B-V1.0",