3 ms·
A bunch of years ago I ended up writing a userpsace C program to essentially split incoming UDP packets to multiple destinations. I could have probably done tha
by IgorPartola 6y ago
A bunch of years ago I ended up writing a userpsace C program to essentially split incoming UDP packets to multiple destinations. I could have probably done that with iptables or some such but partially this was a fun exercise in writing a small C program that did big things. The company I worked for relied on these UDP packets as they were a core part of our business and as we migrated from our platform version 1 to the newly developed version 2 we needed both systems to receive the same stream of data. My little program I called wedge did that really well, down to spoofing the sender’s IP address. This allowed us to make a seamless migration of a huge number of customers without any downtime.
I say all this because I highly recommend playing with Linux’s raw packet interface and learning the structure of IP packets to do so. You can really gleam a ton of interesting info about it that way. Writing your own TCP stack was outside of what I needed but even the comparatively much simpler task of routing UDP packets was really fun and rewarding.
- vlovich123 6y agoWhen you saw raw packets due you mean the libc network APIs or raw sockets? It sounded like the latter but for anyone unaware such sockets require root/special privileges. It’s cool but of more limited general value and can be a security exploit as a user space exploit can launch really nasty network attacks that are otherwise impossible (hence why it’s not made available to user space).
- antoinealb 6y agoThese days can't you do it with CAP_NET_RAW linux capabilities ? It is what is used for ping traceroute et al. if I recall correctly
- vlovich123 6y agoSure but you still need to grant your binary that (eg scripting languages need that for the interpreter itself which isn’t great since all programs get it) and it’s just the administrator of the machine going “I know this is dangerous but I’m deciding to do it anyway”. It doesn’t address the underlying issues (eg if I compromise your binary with this capability I have some pretty powerful capabilities including sniffing all traffic on the machine through a promiscuous socket).
- antoinealb 6y agoDid not think about the interpreted languages use case, thanks for pointing that out.
- IgorPartola 6y agoYes raw sockets and yes it required root privileges. It’s not ideal but this is why this was a good exercise in good C practices. In my case the program was very straightforward so not a lot of attack surface to begin with. But yes overall pretty dangerous stuff. I am sure a comment about rewriting the Linux kernel and every other bit of C in Rust will materialize below sooner or later :)