Code them to do that.
Okay, a bit more detailed answer, taking it from two points of views.
But first, a short story about AIs.
The story is entitled the Chinese Room.
There are two rooms, each closed off from the world save a single slot. Into the slot you can hand a slip of paper, and back out of the slot comes another slip of paper. One of these rooms lives a man who can speak Chinese. In the other I live. I, sadly, cannot speak Chinese.
Fortunately for me, however, I've been given an infinitely large book covering every possible written sentence (or combination of sentences) of Chinese, and my lovely little book has a corresponding response. Google Translate has got nothing on me!
Okay, so a line of Chinese speakers line up at each room, handing in slips of paper to each. The first room, the room where the man who can speak Chinese (cheater!) lives, is able to produce a correct, sensible response (in Chinese) back to each person in line.
However, I won't be bested! When the people hand in a slip of paper to me, I look up the setence in my book, find the perfect response, copy it down and hand the slip of paper back. I don't know a word of Chinese yet I'm able to produce a correct, sensible response in Chinese back.
Ignoring the men inside, are both rooms literate in Chinese? Both rooms can 'read' it and 'speak' it, but only one room has the understanding. Since I have no clue what I'm writing can I speak Chinese?
This is a question that we debate today.
The second room, the room with the book, is a computer program as we know it today; it has no concept of what it is doing, it simply does, because that's all a computer is.
We have yet to figure out practically how to traverse that jump from "a bunch of logical gates that just do what we say" to "an entity with understanding of what it is doing." In fact, we don't even know how to approach that jump.
What does true understanding even mean? How do we code that?
It's theorized that to jump that gap we'll have to have machines fundamentally different than computers we have today; not just more advanced, but fundamentally different.
So back to your quesiton, we have two approaches to the concept of AIs:
AIs are simply sufficiently advanced programs with sufficiently advanced hardware
"Any sufficiently advanced technology is indistinguishable from magic" was once said by a very smart man.
To most (readers and writers of science fiction), this is all AIs are: sufficiently advanced where we wave our hands and exclaim "magic!" ah, erm, I mean, "science!"
Except think about this for a moment; they're not magic. They're just... computers.
No, really, think about this again.
This sort of AI is that they're single pieces or amalgamation that humans (or other software) coded, and that's really all they are. The programs have no greater concept of morality than a calculator does. In fact your calculator has no "concept" of the numbers it's processing; it's just logical gates. It's the man in the room with the book of Chinese; it can perform the operations it was designed to do, and does so fantastically.
There is no morality to code; it just stores objects in memory, stores them in long-term storage, manipulates the two, and accepts input and output. It's just bits being flipped on and off.
Honestly, for this sort of AI, the answer to how to implement AI is just to code it.
And do note: we're not coding morality; there's no point in being that abstract. We're either training actions (and coding the 'learning' mechanism) or directly coding what outputs it provides given inputs. It will never know that squishing a human child is "wrong," in fact it doesn't know anything, it just doesn't respond to that output given the input of its sensors, databases, etc.
As to a virus...
And no single piece of code could be complex and flexible enough to alter all different code to adjust it, so the concept of a virus to do this goes straight out the window. Viruses work by exploiting one, two, or maybe a few vulnerabilities and then doing their thing. They're always very targeted, very specific, and try to deal with the environment only enough to get the job done. A single virus won't be effective against Ubuntu and Windows and iOS and Android and Solaris... and they don't seek to dynamically examine and alter the code they run; the most advanced viruses humanity has ever made have also been the most focused, the most targeted.
No actual, real life virus could possibly be this flexible.
Now to the other possibility...
AIs aren't just code; they're a fundamental revolution in artificial creation
So this is the alternative to the above. The answer is (drum roll please) "we have no way of knowing."
Yep, sorry about that.
The most brilliant computer scientists (and other scientists and engineers in some other fields) in the world are trying to--today--theorize how to jump this gap. We don't yet know how to do this, and we certainly don't know how to build such an AI, or change their behavior after they're built.
Ask this question again in 10, 30, or a 100 years and we might have an answer for you.
Woah, back off the science!
Okay, so you didn't tag this "hard-science" so let's pump the brakes a bit.
Let's hand wave it. Pick either type of AI (just code, or something fundamentally different) describe how it's different in your setting, don't dive too deep into details, and hand wave the rest. In this case go with the virus idea; a computer virus fundamentally describes what you want, an intrusive, unwanted piece of code that bypasses security measures and alters the digital environment's behavior.
You could even make this virus an AI that runs within the AI it's trying to alter, or maybe a small part of the AI (a smaller... whatever, chuck of code, I suppose) that makes callbacks to the parent AI.
As long as you're willing to hand wave and not dive too deep into details, just make the explanation what sounds interesting.
If you want real science though, the answer is just to code the AIs to do their job correctly.
Edit: @RBarryYoung provided the somewhat spirited addition that the Chinese Room example comes from one John Searle. You can read about it further here. Thanks for the credit correct, Mr. Young.