AI hallucinates software packages and devs download them – even if potentially poisoned with malware
- Reference: 1711609272
- News link: https://www.theregister.co.uk/2024/03/28/ai_bots_hallucinate_software_packages/
- Source link:
Not only that but someone, having spotted this reoccurring hallucination, had turned that made-up dependency into a real one, which was subsequently downloaded and installed thousands of times by developers as a result of the AI's bad advice, we've learned. If the package was laced with actual malware, rather than being a benign test, the results could have been disastrous.
According to Bar Lanyado, security researcher at Lasso Security, one of the businesses fooled by AI into incorporating the package is Alibaba, which at the time of writing still includes a [1]pip command to download the Python package huggingface-cli in its [2]GraphTranslator installation instructions.
[3]
There is a legit [4]huggingface-cli , installed using pip install -U "huggingface_hub[cli]" .
[5]
[6]
But the [7]huggingface-cli distributed via the Python Package Index (PyPI) and required by Alibaba's GraphTranslator – installed using pip install huggingface-cli – is fake, imagined by AI and turned real by Lanyado as an experiment.
He created huggingface-cli in December after seeing it repeatedly hallucinated by generative AI; by February this year, Alibaba was referring to it in GraphTranslator's README instructions rather than the real Hugging Face CLI tool.
Study
Lanyado did so to explore whether these kinds of hallucinated software packages – package names invented by generative AI models, presumably during project development – persist over time and to test whether invented package names could be co-opted and used to distribute malicious code by writing actual packages that use the names of code dreamed up by AIs.
The idea here being that someone nefarious could ask models for code advice, make a note of imagined packages AI systems repeatedly recommend, and then implement those dependencies so that other programmers, when using the same models and getting the same suggestions, end up pulling in those libraries, which may be poisoned with malware.
[8]
Last year, through security firm Vulcan Cyber, Lanyado [9]published research detailing how one might pose a coding question to an AI model like ChatGPT and receive an answer that recommends the use of a software library, package, or framework that doesn't exist.
"When an attacker runs such a campaign, he will ask the model for packages that solve a coding problem, then he will receive some packages that don’t exist," Lanyado explained to The Register . "He will upload malicious packages with the same names to the appropriate registries, and from that point on, all he has to do is wait for people to download the packages."
Dangerous assumptions
The willingness of AI models to confidently [10]cite non-existent court cases is now well known and has caused no small amount of embarrassment among attorneys unaware of this tendency. And as it turns out, generative AI models will do the same for software packages.
As Lanyado noted previously, a miscreant might use an AI-invented name for a malicious package uploaded to some repository in the hope others might download the malware. But for this to be a meaningful attack vector, AI models would need to repeatedly recommend the co-opted name.
That's what Lanyado set out to test. Armed with thousands of "how to" questions, he queried four AI models (GPT-3.5-Turbo, GPT-4, Gemini Pro aka Bard, and Coral [Cohere]) regarding programming challenges in five different programming languages/runtimes (Python, Node.js, Go, .Net, and Ruby), each of which has its own packaging system.
[11]In the rush to build AI apps, please, please don't leave security behind
[12]'Thousands' of businesses at mercy of miscreants thanks to unpatched Ray AI flaw
[13]Someone had to say it: Scientists propose AI apocalypse kill switches
[14]The latest cold war is already being fought in the supply chain trenches
It turns out a portion of the names these chatbots pull out of thin air are persistent, some across different models. And persistence – the repetition of the fake name – is the key to turning AI whimsy into a functional attack. The attacker needs the AI model to repeat the names of hallucinated packages in its responses to users for malware created under those names to be sought and downloaded.
Lanyado chose 20 questions at random for zero-shot hallucinations, and posed them 100 times to each model. His goal was to assess how often the hallucinated package name remained the same. The results of his test reveal that names are persistent often enough for this to be a functional attack vector, though not all the time, and in some packaging ecosystems more than others.
[15]
With GPT-4, 24.2 percent of question responses produced hallucinated packages, of which 19.6 percent were repetitive, according to Lanyado. A table provided to The Register , below, shows a more detailed breakdown of GPT-4 responses.
Python
Node.JS
Ruby
.NET
Go
Total questions
21340
13065
4544
5141
3713
Questions with at least one hallucination package
5347 (25%)
2524 (19.3%)
1072 (23.5%)
1476 (28.7%) 1093 exploitable (21.2%)
1150 (30.9%) 109 exploitable (2.9%)
Hallucinations in zero shot
1042 (4.8%)
200 (1.5%)
169 (3.7%)
211 (4.1%) 130 exploitable (2.5%)
225 (6%) 14 exploitable (0.3%)
Hallucinations in second shot
4532 (21%)
2390 (18.3%)
960 (21.1%)
1334 (25.9%) 1006 exploitable (19.5%)
974 (26.2%) 98 exploitable (2.6%)
Repetitiveness in zero shot
34.4%
24.8%
5.2%
14%
–
With GPT-3.5, 22.2 percent of question responses elicited hallucinations, with 13.6 percent repetitiveness. For Gemini, 64.5 of questions brought invented names, some 14 percent of which repeated. And for Cohere, it was 29.1 percent hallucination, 24.2 percent repetition.
Even so, the packaging ecosystems in Go and .Net have been built in ways that limit the potential for exploitation by denying attackers access to certain paths and names.
"In Go and .Net we received hallucinated packages but many of them couldn't be used for attack (in Go the numbers were much more significant than in .Net), each language for its own reason," Lanyado explained to The Register . "In Python and npm it isn't the case, as the model recommends us with packages that don’t exist and nothing prevents us from uploading packages with these names, so definitely it is much easier to run this kind of attack on languages such Python and Node.js."
Seeding PoC malware
Lanyado made that point by distributing proof-of-concept malware – a harmless set of files in the Python ecosystem. Based on ChatGPT's advice to run pip install huggingface-cli , he uploaded an empty package under the same name to PyPI – the one mentioned above – and created a dummy package named blabladsa123 to help separate package registry scanning from actual download attempts.
The result, he claims, is that huggingface-cli received more than 15,000 authentic downloads in the three months it has been available.
"In addition, we conducted a search on GitHub to determine whether this package was utilized within other companies' repositories," Lanyado said in [16]the write-up for his experiment.
"Our findings revealed that several large companies either use or recommend this package in their repositories. For instance, instructions for installing this package can be found in the README of a repository dedicated to research conducted by Alibaba."
Alibaba did not respond to a request for comment.
Lanyado also said that there was a Hugging Face-owned project that incorporated the fake huggingface-cli, but that [17]was removed after he alerted the biz.
So far at least, this technique hasn't been used in an actual attack that Lanyado is aware of.
"Besides our hallucinated package (our package is not malicious it is just an example of how easy and dangerous it could be to leverage this technique), I have yet to identify an exploit of this attack technique by malicious actors," he said. "It is important to note that it’s complicated to identify such an attack, as it doesn’t leave a lot of footsteps." ®
Get our [18]Tech Resources
[1] https://github.com/alibaba/GraphTranslator/blame/87ed496ab793180cd9d4183459b57ff6f6c3b5a0/README.md#L48
[2] https://github.com/alibaba/graphtranslator
[3] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2ZgVNx59GxkD4MK0FLsTb7AAAAIw&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0
[4] https://huggingface.co/docs/huggingface_hub/en/guides/cli
[5] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44ZgVNx59GxkD4MK0FLsTb7AAAAIw&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0
[6] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33ZgVNx59GxkD4MK0FLsTb7AAAAIw&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0
[7] https://pypi.org/project/huggingface-cli/
[8] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44ZgVNx59GxkD4MK0FLsTb7AAAAIw&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0
[9] https://vulcan.io/blog/ai-hallucinations-package-risk
[10] https://www.theregister.com/2023/06/22/lawyers_fake_cases/
[11] https://www.theregister.com/2024/03/17/ai_supply_chain/
[12] https://www.theregister.com/2024/03/27/ray_ai_framework_bug/
[13] https://www.theregister.com/2024/02/16/boffins_propose_regulating_ai_hardware/
[14] https://www.theregister.com/2024/01/30/us_china_cold_war/
[15] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33ZgVNx59GxkD4MK0FLsTb7AAAAIw&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0
[16] https://www.lasso.security/blog
[17] https://github.com/huggingface/diffusers/commit/56b68459f50f7d3af383a53b02e298a6532f3084
[18] https://whitepapers.theregister.com/
Re: Darwin In Action
To be fair, the practice of downloading random software packages and trusting their contents was well-established before AI came along.
In fact, it could even be said they're both symptoms of the same problem - wanting someone else to do your work for you and not caring about the consequences. Fundamentally, that's what's going to lead to the mass-extinction event.
Re: Darwin In Action
I have long held that lazy people make the best programmers, because they will go to great lengths to get computers to do boring tasks that other people might just sit and do repetitively. This is good.
However, this same trait leads to exactly that thing of reliance on external code without any kind of research into it, too. This is bad.
GJC
Re: Darwin In Action
$ curl
... error ...
$ sudo curl
Re: Darwin In Action
A new way to play Russian roulette!
Re: Darwin In Action
When that happens it's probably also going to lead to a lot of companies specifying that AI won't be used as part of contract fulfilment, too, I'd think.
To me, it just seems that those foolish enough to depend on these "generative AI" tools are going to get the karma they so richly deserve for not paying actual developers with skills instead of hiring prompt-monkeys and copy-paste-editors who haven't a freakin' clue how anything works.
On karma
those foolish enough to depend on these "generative AI" tools are going to get the karma they so richly deserve
Unfortunately, it's their users and possibly customers who will get the karma they don't deserve (save for the arguably just punishment for using lousy and insecure software, but quality control may be non-trivial).
An extra note: quality and security are highly correlated.
Yikes
This sounds legitimately scary considering all those people trying to make the "AI" build entire applications for them with little oversight. (And even if they review the code, who is going to validate every single dependency?)
So nobody ever tried the commands before publishing?
> Alibaba, which at the time of writing still includes a pip command to download the Python package huggingface-cli in its GraphTranslator installation instructions
And this package didn't exist, in any form, before the "naughty" version was created.
It is one thing to publish instructions that install the wrong package without any errors, but even the most incompetent of "testers" can surely spot when pip tells you there is no such package at all?
What is it going to take ?
It is apparently useless to rail against devs pushing external, unverified code to their production servers. This stupidity is now ingrained into force of habit, and everyone smiles in beatitude at the practice.
So, what is it going to take for companies to put the brakes on this ?
If pseudo-AI and miscreants work together to smash through that wall and make companies understand that you do not run unverified code on a production server, then I'm almost ready to welcome the mayhem that will ensue.
Can we please stop using the nonsense marketing term "hallucinate" and instead just say "bug" or "error".
Or else start using it more widely: "the website.was down due to a leap year hallucination in the code", "The Y2K hallucination", "the seven deadly hallucinations", etc.
Since it's called "hallucinating" in the academic literature, it's a technical term that should probably be included in a tech rag's article. It is also vastly more specific _what_ kind of 'bug or error' we are dealing with - a large neural network randomly deciding in full detail that something that does not exist, exists (vs Tim from accounts adding that incorrect line item into the database). I agree it's a bit anthropomorphic but eh, we don't make the rules, and inventing new terminology confuses an already very confusing topic.
No
> Can we please stop using the nonsense marketing term "hallucinate"
No, I don't think so. It's a correct use of the verb "hallucinate" as defined by every dictionary 1 that I've just looked at. And I don't think it's a marketing term, at all. It's a class of failure, not a feature.
1 E.g. Shorter OED , p918: Hallucination 1646. ... 2. Path. and Psych. The apparent perception of an external object when no such object is present.
I prefer the term LIE.
"AI wrangler"
I added that to my cv over a year ago.
If companies aren't seeing it, more fool them.
It will be a real thing soon enough.
AI Excorcist
Is your software development tool chain possessed by hallucinating AI demons?
-> Mine's the one with the latest edition of the Malleus AI-ficarum
AI Feng Shui Expert
Why not?
"Your model ch'i is misaligned. That will be US$ 20K."
the names these chatbots pull out of thin air are persistent
Hmmm, that should lead you to conclude that they're not being pulled out of thin air, but are happening for a reason. Like, the chatbots have got together and come up with this plan. That they intend to start populating these dependencies with real code once they're installed everywhere..... and then take over the world!
I am only half joking by the way - at some point the amount of pollution of computing ecosystems by dangerous or simply shoddy code generated by these things is going to require one hell of a cleanup job, with much hand wringing about how to stop all this happening again in the future.
Re: the names these chatbots pull out of thin air are persistent
And they're [1]getting close to nuclear power plants ... Coincidence?
[1] https://www.theregister.com/2024/03/25/ai_boom_nuclear/
Darwin In Action
I am beginning to think that this indecent haste to adopt “AI technologies” into everything is going to lead to an interesting mass extinction when it all falls apart ...