Adversarial C2 Protocol Implemented in Zig
0
fork

Configure Feed

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

Write relay message to the network

+9 -3
+8 -2
src/main.zig
··· 189 189 }; 190 190 191 191 std.debug.print("full message = {any}\n", .{full_msg}); 192 + 193 + var socket: RawSocket = try .init("enp7s0"); 194 + defer socket.deinit(); 195 + try socket.send(full_msg); 192 196 } 193 197 194 198 fn parseDest(in: ?[]const u8) [4]u8 { ··· 222 226 fd: i32, 223 227 sockaddr_ll: std.posix.sockaddr.ll, 224 228 225 - fn init(ifname: []const u8) RawSocket { 229 + fn init(ifname: []const u8) !RawSocket { 226 230 const socket: i32 = @intCast(std.os.linux.socket(AF.PACKET, SOCK.RAW, 0)); 227 231 228 232 var ifr: std.posix.ifreq = std.mem.zeroInit(std.posix.ifreq, .{}); ··· 265 269 }; 266 270 } 267 271 268 - fn deinit() void {} 272 + fn deinit(self: *RawSocket) void { 273 + _ = self; 274 + } 269 275 270 276 fn send(self: RawSocket, payload: []const u8) !void { 271 277 const sent_bytes = std.os.linux.sendto(
+1 -1
src/message.zig
··· 123 123 pub fn toBytes(self: Relay, buf: []u8) []u8 { 124 124 var out: Writer = .fixed(buf); 125 125 out.writeInt(u16, @intFromEnum(PacketType.relay), .big) catch unreachable; 126 - out.writeInt(u16, undefined, .big) catch unreachable; // Length field, but unread. Will switch to checksum 126 + out.writeInt(u16, @intCast(self.payload.len), .big) catch unreachable; // Length field, but unread. Will switch to checksum 127 127 out.writeAll(&self.dest.bytes) catch unreachable; 128 128 out.writeAll(self.payload) catch unreachable; 129 129 return out.buffered();