I can understand that if an astronaut attack an other astronaut inside a spaceship he/she will have to answer to the law of the country which owns the ship but what if the attack happened on the moon?
The answer might be found in Article VIII of the Outer Space Treaty:
A State Party to the Treaty on whose registry an object launched into outer space is carried shall retain jurisdiction and control over such object, and over any personnel thereof, while in outer space or on a celestial body.
So a person on a 'celestial body' (and the Treaty includes the Moon as a celestial body) is under the jurisdiction of the country who registered the launch vehicle which carried them. If they attacked another person while on the Moon, they would be subject to the criminal law of that country.
I believe all space-faring nations have ratified the treaty.
If a crime has already been committed on the moon, then it would probably be handled under the Uniform Code of Military Justice. Given that everyone who has been to the moon as been in the U.S. military. If we colonize the moon in the future then there will need to be a new organization to handle any potential crimes that will probably be committed.