I'm not a software engineer; I both freelance and use my tech skills as extra incentive to hire me into
non-tech positions. (I'm a generalist to my core). So my answer is going to look a bit different than people who've gone into Tech.
However, I feel/felt pretty good, ethically, about all the tech work I've done, which can separated into a few buckets:
* Work for education systems and libraries. Yes, there's a bunch of stupidity and politics, but at the end of the day, I was making things that helped people learn, and that felt pretty good.
* Work for local or small businesses that otherwise wouldn't have their problems solved at all. In these cases, the businesses were either small enough that I knew the owners + how they ran things and could be assured they weren't exploitative dicks or what they did was important enough (e.g. hospice care) that solving problems and saving them time makes my local community better. (If I help the local lingerie place with IT things, they can serve more people and fewer women are uncomfortable, my local hospice running better means more care for my and my friends' parents, etc.)
* Work for non-profits or other organizations whose missions I believe in. I dabbled in nonpartisan political/civics communications work, for example, and I felt just fine using my tech skills to help people understand things like how elections are administered.
The key thing I've found to finding work that doesn't make me hate myself is the funding model of the organization.