use std;
const math = std::import("./math.xur");
fn main() {
let io = std::io;
io::println("1 + 2 = {}", math.add(1, 2));
}> 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.
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.
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.
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(())
}Structs can specify C ABI layout, alignment, endianness and field offsets — useful for parsing binary formats and interacting with native structures.
struct Header {
magic: u32
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();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();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.
| ● | std | import(path), try_import(path), panic(format, ...), argv() |
| ● | std::io | print, println, eprint, eprintln with {} placeholders |
| ● | std::io::c | ANSI colours: red, green, yellow, blue, magenta, cyan, bold, dim |
| ● | std::fmt | format(template, args...) |
| ● | std::fs | read_to_string, read, write, write_bytes, exists, remove, read_dir, create_dir_all, File |
| ● | std::path | join, parent, file_name, stem, extension, is_dir, is_file, exists, absolute |
| std::net | TcpListener, TcpStream, UdpSocket, UnixListener, UnixStream | |
| std::http | get, post, put, patch, delete; Response with status, text, json, headers | |
| ● | std::json | parse(text), stringify(value) |
| ● | std::regex | Regex with is_match, find, find_all, captures, replace, split |
| std::thread | spawn, sleep, JoinHandle::join | |
| std::process | spawn(program, args) an OS child process; Process::pid/kill/wait | |
| ● | std::sync | channel, Sender::send, Receiver::recv; Mutex, lock, try_lock |
| ● | std::math | sqrt, pow, abs, min, max, floor, ceil, sin, cos, atan2, ln, log2, PI, E, clamp, lerp |
| std::env | get, set, remove, vars, current_dir, home_dir, exe_path | |
| ● | std::random | int, float, bool, choice, shuffle, bytes |
| ● | std::hash | crc32, sha256, sha256_bytes, md5 |
| ● | std::mem | size_of::<T>(), align_of::<T>(), from_bytes::<T>(), to_bytes, alloc_page, protect, free_page |
| std::ptr | null, from_int, to_int, offset, pointer arithmetic | |
| ● | std::reflect | fields, get, set, methods, call, variants; layout::<T>(), Layout |
| ● | std::any | type_name::<T>(), type_name_val() |
| std::cli | argument parsing (parse), prompts (prompt, confirm, select, password, editor), table | |
| ● | std::log | structured logging: trace, debug, info, warn, error, subscriber |
| ● | std::time | Instant, Duration, now, elapsed, sleep |
| ● | std::datetime | now, utc_now, formatting, parsing (RFC 3339, custom) |
| ● | std::assert | is_eq, is_ne, is_true, is_false, fail |
| std::gui | desktop GUI with egui: run(title, fn(ui)), Ui with label, button, checkbox, slider_*, text_edit, window, collapsing, horizontal, scroll | |
| ● | std::re | binaries 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: