When you enlisted you took an oath. You swore that you would
[S]upport and defend the Constitution of the United States against all enemies, foreign and domestic; that I will bear true faith and allegiance to the same; and that I will obey the orders of the President of the United States and the orders of the officers appointed over me, according to regulations and the Uniform Code of Military Justice.
Per the UCMJ you are only obligated to follow "lawful orders." This means that if the President or superior officers tell you to do something "unlawful" you are not obligated to follow that order and if you do you are a party to that crime.
Also, you swore to support and defend the Constitution, not the President, not Congress and certainly not Exxon/Mobil.
Article Six of the Constitution states that
[A]ll Treaties made, or which shall be made, under the Authority of the United States, shall be the supreme Law of the Land
What this means is that the UN Charter is the "supreme Law of the Land."
The Chemical Weapons Convention (with its relevancy for the use of white phosphorus)? The "supreme Law of the Land."
Geneva Conventions? You get the point.
But back to the UN Charter and specifically Chapter 7. Article 39 clearly shows who has the power
The Security Council shall determine the existence of any threat to the peace, breach of the peace, or act of aggression and shall make recommendations, or decide what measures shall be taken...
But Article 51 is relevant as well
Nothing in the present Charter shall impair the inherent right of individual or collective self-defence if an armed attack occurs against a Member of the United Nations, until the Security Council has taken measures necessary to maintain international peace and security
These two articles point out the two lawful ways to use force: either you are attacked or the Security Council authorizes the use of force. You might also want to notice that Iraq and Afghanistan are a signatory to the UN Charter as well. This means that while we were not attacked by either country and nor did the UNSC authorize our use of force (which is the primary reason our invasions were illegal), we did attack them - which means those who resist our occupation are doing so lawfully.
Much of the seventh chapter of the UN Charter is based on lessons learned in World War Two. But Article 2 has something important to consider as well
All Members shall refrain in their international relations from the threat or use of force against the territorial integrity or political independence of any state, or in any other manner inconsistent with the Purposes of the United Nations.
Are alarms going off yet? Another important set of principles highly relevant to you is the Nuremberg Principles
Any person who commits an act which constitutes a crime under international law is responsible therefor and liable to punishment.
The fact that internal law does not impose a penalty for an act which constitutes a crime under international law does not relieve the person who committed the act from responsibility under international law.
The fact that a person who committed an act which constitutes a crime under international law acted as Head of State or responsible Government official does not relieve him from responsibility under international law.
The fact that a person acted pursuant to order of his Government or of a superior does not relieve him from responsibility under international law, provided a moral choice was in fact possible to him.
Any person charged with a crime under international law has the right to a fair trial on the facts and law.
The crimes hereinafter set out are punishable as crimes under international law:
(a) Crimes against peace:
(i) Planning, preparation, initiation or waging of a war of aggression or a war in violation of international treaties, agreements or assurances;
(ii) Participation in a common plan or conspiracy for the accomplishment of any of the acts mentioned under (i).
(b) War crimes:
Violations of the laws or customs of war include, but are not limited to, murder, ill-treatment or deportation to slave-labour or for any other purpose of civilian population of or in occupied territory, murder or ill-treatment of prisoners of war, of persons on the seas, killing of hostages, plunder of public or private property, wanton destruction of cities, towns, or villages, or devastation not justified by military necessity.
(c) Crimes against humanity:
Murder, extermination, enslavement, deportation and other inhuman acts done against any civilian population, or persecutions on political, racial or religious grounds, when such acts are done or such persecutions are carried on in execution of or in connexion with any crime against peace or any war crime.
Complicity in the commission of a crime against peace, a war crime, or a crime against humanity as set forth in Principle VI is a crime under international law.
So what have we covered so far in this brief message? You are only obligated to follow lawful orders.
Considering that the UN Security Council did not authorize the use of force in either Iraq or Afghanistan immediately makes it illegal; which is a war of aggression and a "crime against the peace" as defined by the Nuremberg Principles. And since we are a signatory to these treaties that makes them the "supreme Law of the Land" and if you obey these unlawful orders then you are violating the Constitution and thus your oath.
Enlisting in the military is a serious thing. You have important responsibilities that shouldn't be taken lightly. Take the time to know your responsibilities and the applicable laws. I know that going along with the herd is easier. More often than not we learn that the right thing to do is usually the hardest thing to do. If you resist you will most likely be ostracized and the military may violate the law in order to make an example out of you - an example that tells others, "don't even think about it grunt!" I mean, it was Henry Kissinger who said, "Military men are just dumb stupid animals to be used as pawns in foreign policy."
And know that those of us in the anti-war movement got your back if you find the courage and heroism to resist our wars of aggression.