It is perfectly legal for a non-immigrant alien legally residing in the US on a student or work visa to purchase a firearm from an FFL provided that they also have a hunting license or permit issued in the US. Here's how:
The defitiniton of state of residency in 27 CFR 478.11 contains this example:
Example 4. A, an alien, travels to the United States to work for three years in State X. A rents a home in State X, moves his personal possessions into the home, and his family resides with him in the home. A intends to reside in State X during the 3-year period of his employment. A is a resident of State X.
So, first question: Can a non-immigrant alien be a resident of a state? YES
18 USC 922 (b)(3) contains the residency requirement for an FFL to sell a firearm:
(b) It shall be unlawful for any licensed importer, licensed manufacturer, licensed dealer, or licensed collector to sell or deliver—
(3) any firearm to any person who the licensee knows or has reasonable cause to believe does not reside in (or if the person is a corporation or other business entity, does not maintain a place of business in) the State in which the licensee’s place of business is located, except that this paragraph (A) shall not apply to the sale or delivery of any rifle or shotgun to a resident of a State other than a State in which the licensee’s place of business is located if the transferee meets in person with the transferor to accomplish the transfer, and the sale, delivery, and receipt fully comply with the legal conditions of sale in both such States
So, second question: Can a non-immigrant alien meet the requirement in 18 USC 922(b)(3)? YES
18 USC 922 (d)(5) has this requirement for state of residency for a SALE of a firearm from anyone, including an FFL:
(d) It shall be unlawful for any person to sell or otherwise dispose of any firearm or ammunition to any person knowing or having reasonable cause to believe that such person—
(5) who, being an alien—
(A) is illegally or unlawfully in the United States; or
(B) except as provided in subsection (y)(2), has been admitted to the United States under a nonimmigrant visa (as that term is defined in section 101(a)(26) of the Immigration and Nationality Act (8 U.S.C. 1101 (a)(26)));
So, third question: Can a non-immigrant alien meet that requirement to purchase a firearm from an FFL or a private party? YES - if they meet the exception in (y)(2).
18 USC 922 (y)(2):
(y) Provisions Relating to Aliens Admitted Under Nonimmigrant Visas.—
(2) Exceptions.— Subsections (d)(5)(B), (g)(5)(B), and (s)(3)(B)(v)(II) do not apply to any alien who has been lawfully admitted to the United States under a nonimmigrant visa, if that alien is—
(A) admitted to the United States for lawful hunting or sporting purposes or is in possession of a hunting license or permit lawfully issued in the United States;
So, last question: What does a non-immigrant alien need to fall under the exception in 18 USC 922 (y)(2)? See that "OR" highlighted in (y)(2)(A) above? All they need is a hunting license or permit issued in the US.
It is perfectly legal for a non-immigrant alien legally residing in the US on a student or work visa to purchase a firearm from an FFL provided that they also have a hunting license or permit issued in the US.