Very true. It is also easy to be so wrapped up in the trappings of what you're doing and the pleasure/sense of duty/sense of fulfillment you're getting from the actual act of your work and the compensation around it that you stop thinking about the consequences of your actions. This sounds terrible, but it's really just a small variant on the banality of evil.
Solving problems, working on tight deadlines, and getting recognition, status, and money are all things that make a person feel like what they're doing is right. It gives an endorphin high, it's a sign that other people are recognizing their work. I hesitate to use the word "addictive" in this context, but it can certainly be compulsive. It's easy to lose sight of whether what you're doing is what you ought to be doing when the act of doing it is so compelling, financially rewarding, and celebrated by others.
This isn't a justification; it is a warning to anyone coming into this field, a warning that I wish I'd thought more about coming into it. This is something we need to be vigilant about as engineers, because it's easy to look the other way on questionable activities by your business when everything else in your life is becoming enriched by it and they're telling you that the ethical issues are for "their side of the business" to worry about. It is not. Do not believe them. Understand where your paycheck is coming from, and make sure that you continue to evaluate it as your company changes and ask yourself if you're okay with it.
In my career, I have:
* Been lied to about the true purpose of a product we were building, and only realized the lie because another engineer was brave enough to call them out and force them to tell the truth. I was fully prepared to be the coward that didn't follow up on it and remain willfully ignorant, and his ethical bravery was the only thing that snapped me out of it.
* Seen a company's financial plan gradually change from an ethical one to an unethical one, and have seen good people struggle and contort themselves to justify it: including myself, for a time.
* Worked in fields where the profits gained by maintaining the status quo has created a desire for minimium compliance instead of continual improvements.
The mandatory ethics class I took for my CS degree never prepared me for what to do, how to be vigilant, or how to take action when it is the company itself that is the unethical one. I feel like we need to have open and honest discussions with people coming into this field about this very real possibility, and about the need to evaluate not just the compensation and interesting problems being presented by a given business, but also the ways that they earn money and whether it is something you find acceptable. And what to do if that situation takes a turn for the worse.
The ACM has some high-level recommendations in their ethics statements, and I think they're a good start. They should be required reading for all software engineers.
https://ethics.acm.org/
I have been a coward. I have been an example of the banality of evil. And I don't think I'm alone in this field: not by a long shot. We've got to pay attention to the ethics of what we create, and we need to be much more brave than we have been.