Making square torus with square cross section
Steps:


Create a Plane and convert it to Curve - Alt+C > Curve from Mesh/Text.
Add Bezier > Circle.
With Circle selected go to Data tab and choose Plane as a Bevel Object - you will probably need to scale down Plane.
Set Resolution > Preview U to desired density.
Add Solidify modifier and set Thickness. I've used minus value to create "inner" wall.
Convert your curve object to a mesh - Alt+C > Mesh from Curve/Meta/Surf/Text.
Optionally you can add Solidify again.