The most productive thing: Voice dissent. Ensure the higher-ups have thought through their position and the consequences. Assume they know things you don't. Ultimately, follow the order.
Once it's their call, you're absolved of any responsibility. Both morally and in every meaningful sense.
As an extreme example, if a company I worked at decided that they were going to murder someone, I would certainly voice my dissent. If they decided to continue to go through with it, I'd quit.
Sure, that's a bit hyperbolic, but consider companies like Palantir that work on things that actively erode citizen privacy. I'd never work at a company like that, and if my employer suddenly shifted gears to work on things like that, I'd quit.
"Following orders" is for the military... and even then I would hope someone in the armed forces would refuse to comply with an unlawful or otherwise morally horrible order.
Okay, so how do I get my friends to do that is the question. Conveying this requires getting them to admit there is something wrong with what their employer is doing in the first place, and at that point I'd be already past the obstacle I'm trying to figure out how to overcome.
After reading most of the comments, I think you tell them bluntly what you're thinking.
If they listen to you, maybe they'll quit. If you lose their friendship, you can make new ones who don't work for evil companies.
And if they keep doing evil things for a living but still want to be your friend, maybe you should be the one to end the friendship. I've done that a few times. It gets easier with practice.
If your intent is to improve the world, and not just act superior, I don't see what this accomplishes. Hear dissent without action long enough and it becomes noise.
Higherups will usually defend by hiding behind the process - aka the virtual will and orders of the social golem that is a company.
And nobody alone is responsible for the process. There is not necessary a feeling of responsibility on top- just because powers are granted by the process.
Once it's their call, you're absolved of any responsibility. Both morally and in every meaningful sense.