Even if there is not ejaculation, an unprotected penetration, whether it's anal or vaginal exposes both partners to an infection. The contact between a genital mucosa (glans, vaginal or anal in the case of an anal penetration) is enough to cause an infection. The risk increases id there is ejaculation.
Other ways HIV is spread are:
-Sharing needles to inject drugs.
-Mother to child.