I'm not sure that a word exists for the practice of obtaining prescription medications from friends, acquaintances, or (for whatever price the market will bear) from vending strangers. "Med-seeking" we designate the practice of sending health care providers to an early grave with endless and inappropriate pleas for pharmacological relief. "Self-medication" is the hypothesized use of alcohol, most classically, but also illicit drugs in an effort to treat some supposed mental disorder. "Substance abuse" is, well, substance abuse.
But the word I'm looking for involves co-opting the tools of doctors without having to resort to the doctors themselves in the same way that an autodidact bypasses educators or a vigilante bypasses law enforcement. It is surprisingly common for folks, lacking access to a doctor for reasons of money or transportation, to obtain meds from whatever source they can find. To be sure, these are often opioids or benzodiazepines, but by no means always. I saw a woman recently with bipolar disorder who had been obtaining Seroquel samples from her sister, who is a nurse. And if someone is going to run out of Effexor a week before he can get in with a doctor, who could blame him for scrounging up seven doses wherever he can? After all, it's not as if the medical system is flexible and easy to work with.
If someone has been prescribed Xanax for anxiety symptoms with positive results in the past, and finds himself between doctors for whatever logistical reasons, is it wrong for him to obtain Xanax in unconventional ways if he never exceeds a typically prescribed dose? The Drug Enforcement Agency would say yes, presumably, and certainly this isn't a practice one should condone, but does it constitute substance abuse? I don't think so, if he has a legitimate anxiety disorder and no substance abuse history. In this case it would be no different from someone using a friend's unused antibiotics for a (self-diagnosed) sinus infection. And consider that, because doctors are often understandably hypervigilant and restrictive as regards controlled substances, it may be hard even for patients who quite appropriately need and use them to gain access.
To be sure, medicine has a procedure for enabling this practice in cases where it's considered safe: it's called making a drug available over the counter. And doctors have a way of frowning on any circumvention of their alleged wisdom. Indeed, patients who engage in this practice (for which I can't think of a name) may simply have below average respect for authority in general (but perhaps above average resourcefulness). This practice has family resemblances both with people who decide on a medication for themselves based on television commercials and with physicians who liberally prescribe themselves medications (not recommended). All of these undertakings stem from the natural assumption that if you want something done right, you'd better do it yourself. "Self-doctoring" may be the term, but I wish there were something more felicitous...