Skip to content

Commit

Permalink
'zig build' builds all supported archs, 'zig build -Dtarget=arch-os-a…
Browse files Browse the repository at this point in the history
…bi' builds single arch.
  • Loading branch information
michal-z committed Feb 16, 2024
1 parent 790a50c commit 923fee2
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 101 deletions.
154 changes: 80 additions & 74 deletions BOF-collection.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
#
# Coreutils implemented as BOFs
#
---
name: "uname"
description: "Print information about the machine and operating system. Compatible with POSIX uname(1) system command."
author: "Z-Labs"
tags: ['host-recon', 'coreutils']
OS: 'linux'
header: ['inline', 'z']
sources:
- 'https://raw.githubusercontent.com/The-Z-Labs/bof-launcher/main/bofs/src/coreutils/uname.zig'
usage:
'uname [str:OPTION]
Print certain system information. With no OPTION, same as -s.
-a print all information
-s print the kernel name
-n print the network node hostname
-r print the kernel release
-v print the kernel version
-m print the machine hardware name'
examples:"
uname
uname -a
uname -r"


---
name: "udpScanner"
description: "Universal UDP port sweeper"
description: "Universal UDP port sweeper."
author: "Z-Labs"
tags: ['net-recon']
OS: "cross"
Expand All @@ -41,69 +12,104 @@ usage: '
Arguments:
str:IPSpec[:portSpec] ex: 192.168.0.1; 10.0.0-255.1-254; 192.168.0.1:161,427,10-15
[int:BUF_LEN] length of UDP probes buffer
[str:BUF_MEMORY_ADDR] pointer to the buffer containing one or more UDP probe(s). One probe per line is allowed.
str:IPSpec[:portSpec] ex: 192.168.0.1; 10.0.0-255.1-254; 192.168.0.1:161,427,10-15
[int:BUF_LEN] length of UDP probes buffer
[str:BUF_MEMORY_ADDR] pointer to the buffer containing one or more UDP probe(s). One probe per line is allowed.
UDP probe syntax (with example):
<portSpec> <probeName> <hexadecimal encoded probe data>\n
53,69,135,1761 dnsReq 000010000000000000000000'

examples: '
Scanning provided IP range on most common UDP ports with builtin UDP probes:
udpScanner str:192.168.0.1-32
Scanning provided IP range on most common UDP ports with builtin UDP probes:
Scanning only cherry-picked ports (if no builtin UDP probe for the chosen port is available then length and content of the packet payload will be randomly generated:
udpScanner str:192.168.0.1-32
udpScanner str:192.168.0.1:123,161
udpScanner str:102.168.1.1-128:53,427,137
udpScanner str:192.168.0.1:100-200
Scanning only cherry-picked ports (if no builtin UDP probe for the chosen port is available then length and content of the packet payload will be randomly generated:
Example of running with provided UDP probes:
udpScanner str:192.168.0.1:123,161
udpScanner str:102.168.1.1-128:53,427,137
udpScanner str:192.168.0.1:100-200
udpScanner str:192.168.0.1-32 int:BUF_LEN str:BUF_MEMORY_ADDRESS
Example of running with provided UDP probes:
Example of running udpScanner using cli4bofs tool and with UDP probes provided from the file:
udpScanner str:192.168.0.1-32 int:BUF_LEN str:BUF_MEMORY_ADDRESS
cli4bofs exec udpScanner 102.168.1.1-4:161,427 file:/tmp/udpPayloads'
Example of running udpScanner using cli4bofs tool and with UDP probes provided from the file:
#
# Net-tools implemented as BOFs
# TODO: arp (cross-platform)
# https://github.com/ecki/net-tools/blob/master/arp.c
# https://raw.githubusercontent.com/trustedsec/CS-Situational-Awareness-BOF/master/src/SA/arp/entry.c
#
cli4bofs exec udpScanner 102.168.1.1-4:161,427 file:/tmp/udpPayloads'
---
name: uname
description: "Print certain system information. With no FLAGS, same as -s"
author: Z-Labs
tags: ['host-recon']
OS: linux
header: ['inline', '']
sources:
- 'https://raw.githubusercontent.com/The-Z-Labs/bof-launcher/main/bofs/src/coreutils/uname.zig'
usage: '
uname [str:FLAGS]
Flags:
-a print all information
-s print the kernel name
-n print the network node hostname
-r print the kernel release
-v print the kernel version
-m print the machine hardware name
'
examples: '
uname
uname -a
'

#
# Third party BOFs
#
---
name: hostid
description: "Print the numeric identifier for the current host"
author: Z-Labs
tags: ['host-recon']
OS: linux
header: ['inline', '']
sources:
- 'https://raw.githubusercontent.com/The-Z-Labs/bof-launcher/main/bofs/src/coreutils/hostid.zig'
usage: '
hostid
'
examples: '
hostid
'

---
name: "zerologon"
description: "Exploit for CVE-2020-1472, a.k.a. Zerologon. This allows for an attacker to reset the machine account of a target Domain Controller, leading to Domain Admin compromise. **This exploit will break the functionality of this domain controller!**"
author: "Rsmudge"
tags: ['exploit']
OS: "windows"
header: ['inline', 'ZZZ']
name: hostname
description: "Show system host name"
author: Z-Labs
tags: ['host-recon']
OS: linux
header: ['inline', '']
sources:
- 'https://raw.githubusercontent.com/rsmudge/ZeroLogon-BOF/master/src/zerologon.c'
usage: "zerologon <dc_fqdn> <dc_netbios> <dc_account>"
examples:
"zerologon DC.corp.acme.com DC DC$"
- 'https://raw.githubusercontent.com/The-Z-Labs/bof-launcher/main/bofs/src/coreutils/hostname.zig'
usage: '
hostname
'
examples: '
hostname
'

---
name: "arp"
description: "List arp table"
author: "Trustedsec"
tags: ['host recon']
OS: "windows"
name: id
description: "Print user and group information for each specified USER, or (when USER omitted) for the current process"
author: Z-Labs
tags: ['host-recon']
OS: linux
header: ['inline', '']
sources:
- 'https://raw.githubusercontent.com/trustedsec/CS-Situational-Awareness-BOF/master/src/SA/arp/entry.c'
- 'https://raw.githubusercontent.com/trustedsec/CS-Situational-Awareness-BOF/master/src/common/bofdefs.h'
- 'https://raw.githubusercontent.com/trustedsec/CS-Situational-Awareness-BOF/master/src/common/base.c'
usage: "arp"
examples:
"arp"
- 'https://raw.githubusercontent.com/The-Z-Labs/bof-launcher/main/bofs/src/coreutils/id.zig'
usage: '
id [str:USER]
'
examples: '
id
id root
'

75 changes: 50 additions & 25 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,62 @@ fn cpuArchStr(arch: std.Target.Cpu.Arch) []const u8 {
}

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const supported_targets: []const std.Target.Query = &.{
.{ .cpu_arch = .x86, .os_tag = .windows, .abi = .gnu },
.{ .cpu_arch = .x86, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu },
.{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .arm, .os_tag = .linux, .abi = .gnueabihf },
};

const std_target = b.standardTargetOptions(.{ .whitelist = supported_targets });
const optimize = b.option(
std.builtin.Mode,
"optimize",
"Prioritize performance, safety, or binary size (-O flag)",
) orelse .ReleaseSmall;

const zig_yaml_module = b.dependency("zig_yaml", .{
.target = target,
.optimize = optimize,
.log = false,
}).module("yaml");

const bof_launcher_dep = b.dependency("bof_launcher", .{ .optimize = optimize });
const bof_launcher_lib = bof_launcher_dep.artifact("bof_launcher_" ++
comptime osTagStr(@import("builtin").os.tag) ++ "_" ++
cpuArchStr(@import("builtin").cpu.arch));
const bof_launcher_api_module = bof_launcher_dep.module("bof_launcher_api");

const exe = b.addExecutable(.{
.name = "cli4bofs",
.root_source_file = .{ .path = thisDir() ++ "/src/main.zig" },
.target = target,
.optimize = optimize,
});

exe.linkLibrary(bof_launcher_lib);
exe.root_module.addImport("bof-launcher", bof_launcher_api_module);
exe.root_module.addImport("yaml", zig_yaml_module);

b.installArtifact(exe);
const targets_to_build: []const std.Target.Query = if (b.user_input_options.contains("target"))
&.{std_target.query}
else
supported_targets;

for (targets_to_build) |target_query| {
const target = b.resolveTargetQuery(target_query);

const zig_yaml_module = b.dependency("zig_yaml", .{
.target = target,
.optimize = optimize,
}).module("yaml");

const bof_launcher_dep = b.dependency("bof_launcher", .{ .optimize = optimize });
const bof_launcher_lib = bof_launcher_dep.artifact(
std.mem.join(
b.allocator,
"_",
&.{ "bof_launcher", osTagStr(target.result.os.tag), cpuArchStr(target.result.cpu.arch) },
) catch unreachable,
);
const bof_launcher_api_module = bof_launcher_dep.module("bof_launcher_api");

const exe = b.addExecutable(.{
.name = std.mem.join(
b.allocator,
"_",
&.{ "cli4bofs", osTagStr(target.result.os.tag), cpuArchStr(target.result.cpu.arch) },
) catch unreachable,
.root_source_file = .{ .path = thisDir() ++ "/src/main.zig" },
.target = target,
.optimize = optimize,
});

exe.linkLibrary(bof_launcher_lib);
exe.root_module.addImport("bof-launcher", bof_launcher_api_module);
exe.root_module.addImport("yaml", zig_yaml_module);

b.installArtifact(exe);
}
}

inline fn thisDir() []const u8 {
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
.dependencies = .{
.bof_launcher = .{
.url = "https://github.com/The-Z-Labs/bof-launcher/archive/14125449fb9f353dd1abb559977ad4e395074106.tar.gz",
.hash = "12203231b40cae0d102664c0bce5aa400b9eb19e6fbc896fb40a60592ca218ce224f",
.url = "https://github.com/The-Z-Labs/bof-launcher/archive/038c4b5a5002ba3ee76f6a27bd598937dfe775c3.tar.gz",
.hash = "1220dc54ad0c1a7de2006b509c9b72d81d401f99a268603ea02155246d391b3a0049",
},
.zig_yaml = .{
.url = "https://github.com/kubkon/zig-yaml/archive/953bf8e9a10386eb3756d3fc722df634d0d634a9.tar.gz",
Expand Down

0 comments on commit 923fee2

Please sign in to comment.