xur_

> scripting for security research

xur_

PoCs · binaries · processes · reverse engineering

A scripting language for security research — PoC development, binary analysis, process inspection, and reverse engineering, with Rust-like syntax and direct access to native tooling through facet reflection.

try it below open the lab

v0.1.8 · early development · MIT OR Apache-2.0

> run it here

Xur compiled to WebAssembly, running in your browser. Pick an example, edit, Ctrl+Enter.

┌ main.xur

loading xur…

The browser build has no processes, threads or sockets; std::fs is in memory. For your own files, use the lab.

> what it looks like

On your machine, xur talks to real processes and binaries. These run with the native xur CLI.

use std::io;
use std::re::proc;

fn main() -> Result<()> {
    let handle = proc::open_current()?;
    let base = handle.modules()?[0].base;
    io::println("bytes at {}: {}", base.to_hex(), handle.read(base, 4)?.to_hex());
    Ok(())
}

> the language

Xur has Rust-like syntax — let, fn, struct, enum, impl, match, if/else, closures, generics — but is dynamically checked: types you write are enforced when a value arrives, leave them out and anything goes.

┌Modules are values
use std;

const math = std::import("./math.xur");

fn main() {
    let io = std::io;
    io::println("1 + 2 = {}", math.add(1, 2));
}
┌Errors are values: Result and ?

Option and Result are ordinary enums, with their methods (unwrap, map, is_ok, ...) written in Xur in the prelude. ? returns early with the Err or None, otherwise unwraps the value.

fn main() -> Result<(), str> {
    let config = std::fs::read_to_string("config.txt")?;
    std::io::println("{}", config);
    Ok(())
}
┌Control over memory layout

Structs can specify C ABI layout, alignment, endianness and field offsets — useful for parsing binary formats and interacting with native structures.

#[repr(C)]
#[endian(Little)]
struct Header {
    magic: u32
    #[field(offset=8)] payload_size: u32
}

let data = Header { magic: 0xdeadbeef, payload_size: 256 }.to_bytes();
let parsed = std::mem::from_bytes::<Header>(data);

let entry = std::reflect::Layout::new("Entry").field("id", u16).bytes("name", 8).packed();
┌Threads, channels and sockets
let (sender, receiver) = std::sync::channel();
std::thread::spawn(|| sender.send(6 * 7).unwrap());
io::println("{}", receiver.recv().unwrap()); // 42

let listener = std::net::TcpListener::bind("127.0.0.1:7878").unwrap();
let (client, peer) = listener.accept().unwrap();
client.write(client.read_line().unwrap()).unwrap();
┌Enum introspection

All enums — user-defined, #[repr], and native — have built-in methods:

enum Color { Red  Green  Blue }

Color::Red.to_str()      // "Red"
Color::from_str("Red")   // Some(Color::Red)
Color::len()             // 3
Color::values()          // [Color::Red, Color::Green, Color::Blue]

> std

Written in Rust, registered like any native module. ● also in the browser.

●stdimport(path), try_import(path), panic(format, ...), argv()
●std::ioprint, println, eprint, eprintln with {} placeholders
●std::io::cANSI colours: red, green, yellow, blue, magenta, cyan, bold, dim
●std::fmtformat(template, args...)
●std::fsread_to_string, read, write, write_bytes, exists, remove, read_dir, create_dir_all, File
●std::pathjoin, parent, file_name, stem, extension, is_dir, is_file, exists, absolute
std::netTcpListener, TcpStream, UdpSocket, UnixListener, UnixStream
std::httpget, post, put, patch, delete; Response with status, text, json, headers
●std::jsonparse(text), stringify(value)
●std::regexRegex with is_match, find, find_all, captures, replace, split
std::threadspawn, sleep, JoinHandle::join
std::processspawn(program, args) an OS child process; Process::pid/kill/wait
●std::syncchannel, Sender::send, Receiver::recv; Mutex, lock, try_lock
●std::mathsqrt, pow, abs, min, max, floor, ceil, sin, cos, atan2, ln, log2, PI, E, clamp, lerp
std::envget, set, remove, vars, current_dir, home_dir, exe_path
●std::randomint, float, bool, choice, shuffle, bytes
●std::hashcrc32, sha256, sha256_bytes, md5
●std::memsize_of::<T>(), align_of::<T>(), from_bytes::<T>(), to_bytes, alloc_page, protect, free_page
std::ptrnull, from_int, to_int, offset, pointer arithmetic
●std::reflectfields, get, set, methods, call, variants; layout::<T>(), Layout
●std::anytype_name::<T>(), type_name_val()
std::cliargument parsing (parse), prompts (prompt, confirm, select, password, editor), table
●std::logstructured logging: trace, debug, info, warn, error, subscriber
●std::timeInstant, Duration, now, elapsed, sleep
●std::datetimenow, utc_now, formatting, parsing (RFC 3339, custom)
●std::assertis_eq, is_ne, is_true, is_false, fail
std::guidesktop GUI with egui: run(title, fn(ui)), Ui with label, button, checkbox, slider_*, text_edit, window, collapsing, horizontal, scroll
●std::rebinaries with pewter (pe, elf), live processes with procodile (proc), x86 disassembly/assembly with iced-x86 (asm::x86), .NET assemblies with hao (dotnet), and Unity Il2Cpp with hao-il2cpp (dotnet::il2cpp)

> how it works

source ─▶ lexer ─▶ parser ─▶ AST ─▶ name resolution ─▶ bytecode ─▶ VM
                                    (follows imports)   (lowered on first call)

The bytecode is a control-flow graph of basic blocks over virtual registers, shaped like Cranelift's IR so that a JIT can later compile the same code the interpreter runs; see ARCHITECTURE.md for the whole journey. xur debug shows each stage:

> install

$ cargo install xur
$ xur run hello.xur
$ xur debug bytecode hello.xur
$ xur lsp   # language server