Skip to content

Commit 45c413e

Browse files
author
il1v3y
committed
ci: Fix syntax error and align codebase with Zig 0.15.2 modern APIs
1 parent ce14b00 commit 45c413e

6 files changed

Lines changed: 90 additions & 71 deletions

File tree

src/agent.zig

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,15 @@ pub const Agent = struct {
125125
const conn = try std.net.tcpConnectToAddress(address);
126126
defer conn.close();
127127

128-
var bw = std.io.bufferedWriter(conn.writer());
129-
const reader = conn.reader();
130-
131-
try self.sendPing(&bw, reader);
132-
try self.checkTasks(&bw, reader);
128+
var read_buf: [4096]u8 = undefined;
129+
var write_buf: [4096]u8 = undefined;
130+
var r_state = conn.reader(&read_buf);
131+
var w_state = conn.writer(&write_buf);
132+
const reader = r_state.interface();
133+
const writer = &w_state.interface;
134+
135+
try self.sendPing(writer, reader);
136+
try self.checkTasks(writer, reader);
133137
}
134138

135139
fn sendPing(self: *Agent, writer: anytype, reader: anytype) !void {
@@ -320,12 +324,11 @@ pub const Agent = struct {
320324
if (resp) |r| self.allocator.free(r);
321325
}
322326

323-
fn sendEncrypted(self: *Agent, bw: anytype, plaintext: []const u8) !void {
327+
fn sendEncrypted(self: *Agent, writer: anytype, plaintext: []const u8) !void {
324328
const encrypted = try crypto.encrypt(self.allocator, self.key, plaintext);
325329
defer self.allocator.free(encrypted);
326-
try bw.writer().writeInt(u32, @as(u32, @intCast(encrypted.len)), .little);
327-
try bw.writer().writeAll(encrypted);
328-
try bw.flush();
330+
try writer.writeInt(u32, @as(u32, @intCast(encrypted.len)), .little);
331+
try writer.writeAll(encrypted);
329332
}
330333

331334
fn receiveEncrypted(self: *Agent, reader: anytype) !?[]u8 {

src/c2.zig

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const std = @import("std");
2-
const ArrayList = std.array_list.Managed;
32

43
pub const default_state_file = ".zighound_c2_sim.txt";
54

@@ -29,15 +28,15 @@ pub const Command = struct {
2928

3029
pub const C2State = struct {
3130
allocator: std.mem.Allocator,
32-
beacons: ArrayList(Beacon),
33-
commands: ArrayList(Command),
31+
beacons: std.ArrayListUnmanaged(Beacon),
32+
commands: std.ArrayListUnmanaged(Command),
3433
next_command_id: u64,
3534

3635
pub fn init(allocator: std.mem.Allocator) C2State {
3736
return .{
3837
.allocator = allocator,
39-
.beacons = ArrayList(Beacon).init(allocator),
40-
.commands = ArrayList(Command).init(allocator),
38+
.beacons = .empty,
39+
.commands = .empty,
4140
.next_command_id = 1,
4241
};
4342
}
@@ -54,8 +53,8 @@ pub const C2State = struct {
5453
self.allocator.free(command.status);
5554
self.allocator.free(command.output);
5655
}
57-
self.beacons.deinit();
58-
self.commands.deinit();
56+
self.beacons.deinit(self.allocator);
57+
self.commands.deinit(self.allocator);
5958
}
6059
};
6160

@@ -92,7 +91,7 @@ pub fn loadState(allocator: std.mem.Allocator, path: []const u8) !C2State {
9291
const jitter = std.fmt.parseInt(u32, jitter_str, 10) catch return StateError.InvalidStateLine;
9392
const last_callback = std.fmt.parseInt(i64, last_callback_str, 10) catch return StateError.InvalidStateLine;
9493

95-
try state.beacons.append(.{
94+
try state.beacons.append(state.allocator, .{
9695
.id = id,
9796
.listener = listener,
9897
.jitter = jitter,
@@ -113,7 +112,7 @@ pub fn loadState(allocator: std.mem.Allocator, path: []const u8) !C2State {
113112

114113
if (id >= state.next_command_id) state.next_command_id = id + 1;
115114

116-
try state.commands.append(.{
115+
try state.commands.append(state.allocator, .{
117116
.id = id,
118117
.beacon_id = beacon_id,
119118
.command = command_text,
@@ -168,7 +167,7 @@ pub fn registerBeacon(state: *C2State, listener: []const u8, jitter: u32) ![]con
168167
const status = try state.allocator.dupe(u8, "active");
169168
const now = std.time.timestamp() * 1000;
170169

171-
try state.beacons.append(.{
170+
try state.beacons.append(state.allocator, .{
172171
.id = id,
173172
.listener = listener_copy,
174173
.jitter = jitter,
@@ -193,7 +192,7 @@ pub fn queueCommand(state: *C2State, beacon_id: []const u8, command: []const u8)
193192
const status = try state.allocator.dupe(u8, "queued");
194193
const output = try state.allocator.dupe(u8, "");
195194

196-
try state.commands.append(.{
195+
try state.commands.append(state.allocator, .{
197196
.id = command_id,
198197
.beacon_id = beacon_copy,
199198
.command = command_copy,

src/privesc.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub const PrivEsc = struct {
1515
}
1616

1717
pub fn audit(self: *PrivEsc) ![]u8 {
18-
var report = ArrayList(u8).init(self.allocator);
19-
defer report.deinit();
20-
const writer = report.writer();
18+
var report: std.ArrayListUnmanaged(u8) = .empty;
19+
defer report.deinit(self.allocator);
20+
const writer = report.writer(self.allocator);
2121

2222
try writer.print("=== Privilege Escalation Audit ===\n", .{});
2323

@@ -29,7 +29,7 @@ pub const PrivEsc = struct {
2929
try writer.print("[-] OS not supported for automated audit.\n", .{});
3030
}
3131

32-
return report.toOwnedSlice();
32+
return report.toOwnedSlice(self.allocator);
3333
}
3434

3535
fn auditLinux(self: *PrivEsc, writer: anytype) !void {

src/scanner.zig

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
// Proprietary and confidential.
44

55
const std = @import("std");
6+
67
const builtin = @import("builtin");
8+
79
const util = @import("util.zig");
8-
const os = if (@hasDecl(std, "posix")) std.posix else os;
9-
const ArrayList = std.array_list.Managed;
10+
11+
const os = if (@hasDecl(std, "posix")) std.posix else std.os;
12+
13+
1014

1115
pub const Scanner = struct {
16+
1217
allocator: std.mem.Allocator,
13-
results: ArrayList(ScanResult),
18+
19+
results: std.ArrayListUnmanaged(ScanResult),
20+
21+
1422

1523
pub const ReportFormat = enum {
1624
auto,
@@ -62,7 +70,7 @@ pub const Scanner = struct {
6270
pub fn init(allocator: std.mem.Allocator) Scanner {
6371
return .{
6472
.allocator = allocator,
65-
.results = ArrayList(ScanResult).init(allocator),
73+
.results = .empty,
6674
};
6775
}
6876

@@ -71,7 +79,7 @@ pub const Scanner = struct {
7179
self.allocator.free(result.ip);
7280
if (result.banner) |b| self.allocator.free(b);
7381
}
74-
self.results.deinit();
82+
self.results.deinit(self.allocator);
7583
}
7684

7785
pub fn scanTarget(
@@ -81,7 +89,7 @@ pub const Scanner = struct {
8189
options: ScanOptions,
8290
) !void {
8391
var ports_list = try parsePorts(self.allocator, ports_str);
84-
defer ports_list.deinit();
92+
defer ports_list.deinit(self.allocator);
8593

8694
const range = try parseTarget(target);
8795
const host_count: u64 = @as(u64, range.end) - @as(u64, range.start) + 1;
@@ -162,7 +170,7 @@ pub const Scanner = struct {
162170

163171
const Shared = struct {
164172
allocator: std.mem.Allocator,
165-
results: *ArrayList(ScanResult),
173+
results: *std.ArrayListUnmanaged(ScanResult),
166174
verbose: bool,
167175
quiet: bool,
168176
color: bool,
@@ -219,7 +227,7 @@ pub const Scanner = struct {
219227

220228
var stored = false;
221229
shared.results_mutex.lock();
222-
shared.results.append(result) catch {};
230+
shared.results.append(shared.allocator, result) catch {};
223231
shared.open_count += 1;
224232
stored = true;
225233
shared.results_mutex.unlock();
@@ -383,8 +391,8 @@ pub const Scanner = struct {
383391
return .{ .start = start, .end = end };
384392
}
385393

386-
fn parsePorts(allocator: std.mem.Allocator, ports_str: []const u8) !ArrayList(u16) {
387-
var ports = ArrayList(u16).init(allocator);
394+
fn parsePorts(allocator: std.mem.Allocator, ports_str: []const u8) !std.ArrayListUnmanaged(u16) {
395+
var ports: std.ArrayListUnmanaged(u16) = .empty;
388396

389397
const included = try allocator.alloc(bool, 65_536);
390398
defer allocator.free(included);
@@ -408,15 +416,15 @@ pub const Scanner = struct {
408416
const port = @as(u16, @intCast(port_value));
409417
const index = @as(usize, port);
410418
if (!included[index]) {
411-
try ports.append(port);
419+
try ports.append(allocator, port);
412420
included[index] = true;
413421
}
414422
}
415423
} else {
416424
const port = try parsePortValue(token);
417425
const index = @as(usize, port);
418426
if (!included[index]) {
419-
try ports.append(port);
427+
try ports.append(allocator, port);
420428
included[index] = true;
421429
}
422430
}

0 commit comments

Comments
 (0)