All persons in the military or naval service of the United States are prohibited from buying or selling, trading, or in any way dealing in captured or abandoned property, whereby they shall receive or expect any profit, benefit, or advantage to themselves, or any other person, directly or indirectly connected with them; and it shall be the duty of such person whenever such property comes into his possession or custody, or within his control, to give notice thereof to some agent, appointed by virtue of this chapter, and to turn the same over to such agent without delay. Any officer of the United States, civil, military, or naval, or any sutler, soldier, or marine, or other person who shall violate any provision of this section, shall be deemed guilty of a misdemeanor, and shall be fined not more than $5,000, and imprisoned in the penitentiary not more than three years. Violations of this section shall be cognizable before any court, civil or military, competent to try the same.