The invention relates to a chemical used for aluminum and magnesium alloys, particularly relates to a cleaning agent having cleaning, degreasing and brightening functions for aluminum alloys and magnesium alloy, and belongs to the technical field of chemicals. The agent includes, by weight, 8-10 parts of an organic amine, 3-7 parts of a water-soluble organic solvent, 3-8 parts of a corrosion inhibitor, 0.5-1 part of a color change preventing agent, 2-4 parts of fatty acid soap, 1-3 parts of a surfactant, 3-6 parts of a complexing agent and 60-80 parts of a solvent. The anti-oxidation, anticorrosion, degreasing and brightening agent for aluminum and magnesium alloys, which is reasonable in compatibility, has good cleaning and polishing effects on aluminum alloys and magnesium alloys, makesa cleaned sample bright and clean, and protects the sample from being blackened or darkened in a certain period of time after cleaning, and allows a material to have deactivation, anti-oxidation, andanticorrosion effects and the like. The disclosed degreasing and brightening agent does not contain sulfur, phosphorus, or the like, and is low in environment pollution, and after-treatment of a wasteliquid is simple.