The Insecta class comprises approximately 1.000.000 species distributed in 32 orders . The excretory system in insects and terrestrial arthropods consists of structures called Malpighian tubules. This organ, like the posterior intestine forms the primary system in insects for ionic, osmotic and excretory regulation by which excretion products and toxic compounds are transported. The final phase of excretion occurs in the rectum, with ions and water is reabsorbed at this location.
For more details go through the link