Adversarial C2 Protocol Implemented in Zig
0
fork

Configure Feed

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

+40 -11
+40 -11
src/main.zig
··· 97 97 const linux_socket = std.os.linux.socket(AF.PACKET, SOCK.RAW, 0); 98 98 const errno = std.os.linux.errno(linux_socket); 99 99 if (errno != .SUCCESS) { 100 - std.debug.log("Failed to open socket: {t}\n", .{errno}); 100 + std.debug.print("Failed to open socket: {t}\n", .{errno}); 101 101 return error.Error; // TODO: better error 102 102 } 103 103 break :blk linux_socket; 104 104 }; 105 105 const socket_fd = blk: { 106 - const socket_fd = std.os.linux.bind(linux_socket, @bitCast(std.os.linux.sockaddr.ll{ 107 - .protocol = , 106 + const socket_fd = std.os.linux.bind(@intCast(linux_socket), @bitCast(std.os.linux.sockaddr.ll{ 107 + // https://codeberg.org/jeffective/gatorcat/src/commit/1da40c85c2d063368e2e5c130e654cb32b6bff0e/src/module/nic.zig#L137 108 + .protocol = std.mem.nativeToBig(u16, @as(u16, std.os.linux.ETH.P.ALL)), 108 109 .ifindex = 1, 109 - .hatype = , 110 - .pkttype = , 111 - .halen = , 110 + .hatype = 0, 111 + .pkttype = 0, 112 + .halen = 0, 112 113 .addr = @splat(0), 113 - }), @sizeOf(std.os.linux.sockaddr.ll)); 114 + }), @sizeOf(std.os.linux.sockaddr.ll)); 115 + 116 + const errno = std.os.linux.errno(socket_fd); 117 + 118 + if (errno != .SUCCESS) { 119 + std.debug.print("Failed to create link layer socket: {t}\n", .{errno}); 120 + return error.Error; // TODO: better error 121 + } 122 + break :blk socket_fd; 114 123 }; 115 - const ip: std.Io.net.IpAddress = .{ .ip4 = .unspecified(0) }; 116 - const socket = try ip.bind(init.io, .{ .mode = .raw, .protocol = .raw }); 117 - defer socket.close(init.io); 118 124 119 - try socket.send(init.io, &.{ .ip4 = try .parse("255.255.255.255", 8888) }, "foo"); 125 + const EthIpUdp = struct { 126 + // eth 127 + dst_mac: [6]u8 = @splat(0xff), 128 + src_mac: [6]u8, 129 + eth_type: u16 = std.os.linux.ETH.P.IP, 130 + // ip 131 + ip_version: u4 = 4, 132 + }; 133 + 134 + // const ip: std.Io.net.IpAddress = .{ .ip4 = .unspecified(0) }; 135 + // const socket = try ip.bind(init.io, .{ .mode = .rdm, .protocol = .raw }); 136 + // defer socket.close(init.io); 137 + 138 + // try socket.send(init.io, &.{ .ip4 = .{ .bytes = @splat(255), .port = 8888 } }, "foo"); 120 139 121 140 // var sock_buffer: [1500]u8 = undefined; 122 141 // var raw_socket_writer: RawSocketWriter = try .init("enp7s0", &sock_buffer); // /proc/net/dev ··· 169 188 const SaprusClient = zaprus.Client; 170 189 const SaprusMessage = zaprus.Message; 171 190 const RawSocketWriter = zaprus.RawSocketWriter; 191 + 192 + // Import C headers for network constants and structs 193 + const c = @cImport({ 194 + @cInclude("sys/socket.h"); 195 + @cInclude("linux/if_packet.h"); 196 + @cInclude("net/ethernet.h"); 197 + @cInclude("sys/ioctl.h"); 198 + @cInclude("net/if.h"); 199 + @cInclude("arpa/inet.h"); 200 + }); 172 201 173 202 const AF = std.os.linux.AF; 174 203 const SOCK = std.os.linux.SOCK;