ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

The hidden dangers of loading open-source AI models (ARBITRARY CODE EXPLOIT!)

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ส.ค. 2024

ความคิดเห็น • 110

  • @YannicKilcher
    @YannicKilcher  ปีที่แล้ว +11

    OUTLINE:
    0:00 - Introduction
    1:10 - Sponsor: Weights & Biases
    3:20 - How Hugging Face models are loaded
    5:30 - From PyTorch to pickle
    7:10 - Understanding how pickle saves data
    13:00 - Executing arbitrary code
    15:05 - The final code
    17:25 - How can you protect yourself?
    Try the model: huggingface.co/ykilcher/totally-harmless-model
    Get the code: github.com/yk/patch-torch-save
    Sponsor: Weights & Biases
    Go here: wandb.me/yannic

    • @henrythegreatamerican8136
      @henrythegreatamerican8136 ปีที่แล้ว

      Lovely.... I already downloaded the Stable Diffusion open source v1.4 off Hugging Face a few days ago. Now I'm worried. Anything I can do after the fact?

    • @DaivoHelloworld
      @DaivoHelloworld ปีที่แล้ว

      TGO th-cam.com/video/2Hqc2QA5aU4/w-d-xo.html🌐📊📲🛰️✅🔚✔️🚀📉🆒🕶️🛰️📸☢️Tap on a clip to paste it in the text box.

  • @Wrathofgod220
    @Wrathofgod220 ปีที่แล้ว +63

    I always new pickle was unsafe, but I never understood the programmatic underpinnings that of how pickle worked behind the scenes. Thanks for sharing.

  • @ashwinjayaprakash7991
    @ashwinjayaprakash7991 ปีที่แล้ว +11

    This is awesome. in one video you have not only explained how you went about finding the exploit but also went full circle of how to give back to open source!

  • @Artorias920
    @Artorias920 ปีที่แล้ว +16

    Best AI youtube channel, hands down

  • @qeter129
    @qeter129 ปีที่แล้ว +5

    Thanks for the notice, almost watched the whole ad. Pretty good open for a vulnerability video.

  • @CantLoseTheBlues
    @CantLoseTheBlues ปีที่แล้ว +3

    Thanks for the video. I've used pickle endless times and was never aware of this pitfall. Also, thanks for the very understandable explanation of the technical details.

  • @Corianas_
    @Corianas_ ปีที่แล้ว +4

    Thank you. I had been meaning to look at pickle properly for a while now. This has been a wonderful rundown, and explains some of the warnings I saw when people were discussing pickle, yet I hadn't realized precisely why it was so powerful/dangerous.
    Edit: possibly we need a text extractor for pickled data that doesn't try and do anything other than reveal the contents in a human readable format.
    Edit 2, your explanation allowed me to understand whats going on under the hood, and I was able to use this new knowledge to my advantage already, Thank you again, and 3 thumbs up.

  • @HFLlightning
    @HFLlightning ปีที่แล้ว +16

    Love your videos, keep up the good work!

  • @jossef12
    @jossef12 11 หลายเดือนก่อน

    This is awesome! I gave a talk today at my company to raise awareness of malicious code in AI models. Thanks for sharing! very useful examples.

  • @klin1klinom
    @klin1klinom ปีที่แล้ว +2

    Thanks. Instructions are very clear. I will be loading every model I can get my hands on.

  • @carlossegura403
    @carlossegura403 ปีที่แล้ว +1

    I’ve been using wandb for months nonstop 🔥

  • @Mo-zi4qn
    @Mo-zi4qn ปีที่แล้ว +12

    Hey yannic, I think it would be cool if we get to see what you're working on from day to day (if possible), an example of your current projects and your day to day relationship with machine learning. Im curious because I'm at a stage where I dont know what I want to do with my current base knowledge and skills in machine learning, so this would be inspirational.
    Thanks.

  • @Rex_793
    @Rex_793 ปีที่แล้ว

    Wow really cool that you contacted them and made them aware before releasing this video too!

  • @Fofsl
    @Fofsl ปีที่แล้ว +16

    Nice video, thank you! I avoided this problem by using ONNX models. Does any1 know whether there are security holes for these models?

    • @matthieumaitre7298
      @matthieumaitre7298 ปีที่แล้ว +1

      There is a PoC of ONNX malware on GitHub repo alkaet/LobotoMl but the attack path does not appear complete yet (requires custom-op registration).

  • @alexmallen5765
    @alexmallen5765 ปีที่แล้ว +11

    Awareness is very much a double-edged sword, since it also gives people the idea to make the malware. It only takes one person to make malware, but it takes everyone to go out of their way to be careful to avoid these attacks.

    • @willrazen
      @willrazen ปีที่แล้ว +11

      No it's not, security by obscurity doesn't work. Cybersecurity 101

  • @itachi2011100
    @itachi2011100 ปีที่แล้ว

    TLDR; Old man finds out about deserialization exploits.
    It's surprising how few people understand how deserialization works and what sort of dangers lurks in deserializing untrusted data, great explanation!

  • @SaHaRaSquad
    @SaHaRaSquad ปีที่แล้ว +1

    Now the next step would be a rickrolling model.

  • @Henry_Okinawa
    @Henry_Okinawa ปีที่แล้ว +1

    Haha, OMG I can't believe they use pickle as it is in torch (and huggingface). Pickle is not save to use. Thanks Yannic.

  • @xXxBladeStormxXx
    @xXxBladeStormxXx ปีที่แล้ว +6

    Not as hopeless as you might think. Any medium to large sized tech company that's concerned with security can run models in a sandboxed environment. You could run something like strace to figure out what system calls the program is using and disallow most/all by default, whitelisting them one by one.

    • @Terszel
      @Terszel ปีที่แล้ว

      This sounds like a simple solution - strace, execute the reduce method, see what happens, then use that info to generate a file that shows user what syscalls will be made when you load that model. User can accept or deny. But even this is pretty easy to workaround, at the end of the day it is an insecure method of hosting content

  • @tinylittleanj2
    @tinylittleanj2 ปีที่แล้ว

    Thanks for the video Yannic!
    this is just one of those occasions where I need to find some time somewhere to actually dig into the code a bit more!

  • @binjianxin7830
    @binjianxin7830 ปีที่แล้ว +1

    A more elegant alternative to patch_torch_save seems to be a function decorator as a function factory.

  • @lokeshk4864
    @lokeshk4864 ปีที่แล้ว

    U made it simple man ur subscribers are well deserved

  • @wadahadlan
    @wadahadlan ปีที่แล้ว

    You’re doing the Lords Work, thanks for bringing this up to the community!!

  • @DeadtomGCthe2nd
    @DeadtomGCthe2nd ปีที่แล้ว +5

    according to the youtubes, I hit the first like! yeet

  • @vanderkarl3927
    @vanderkarl3927 ปีที่แล้ว +2

    You should make a hugging face model that exploits this to open this video on the victim's machine, haha

  • @drhilm
    @drhilm ปีที่แล้ว

    I didnt realized that pytorch uses pickle!. Thanks.

  • @Parisneo
    @Parisneo ปีที่แล้ว

    This is very interesting. I was not aware of these problems! Thanks!!!

  • @SuperGanga2010
    @SuperGanga2010 ปีที่แล้ว

    My recommendation is to run untrusted packages and models in Docker containers. This limits the blast radius if you do accidentally run malicious code.

  • @rajeshkannanmj
    @rajeshkannanmj ปีที่แล้ว

    Thanks for doing wonderful things to the society.

  • @christopherhong7004
    @christopherhong7004 ปีที่แล้ว

    Thank you for making us aware, big security risk that should be fixed

  • @keyandkey7599
    @keyandkey7599 ปีที่แล้ว

    The "where did it go" part is so ryt now

  • @AngelicaFWhite
    @AngelicaFWhite ปีที่แล้ว

    Great information. Thank you for sharing this video.

  • @danielsweeney8164
    @danielsweeney8164 ปีที่แล้ว

    Wow an ad for development tools in your vid, thats saying something.

  • @TheRandomdude136
    @TheRandomdude136 ปีที่แล้ว

    This is so cool, props

  • @almamendoza-li7cn
    @almamendoza-li7cn ปีที่แล้ว

    What up buddy Long x no se en Yannic God Bless You brother

  • @dark808bb8
    @dark808bb8 ปีที่แล้ว

    This is generally useful python knowledge. Thanks for sharing!!!!

  • @RealmRabbit
    @RealmRabbit ปีที่แล้ว

    I'm now researching all the pages I looked at and I'm determining which models I downloaded are considered safe, which need to be purged, and which have a good amount of likes/downloads but are still pickles and still may need to be purged...
    I don't think there is any model worth risking viruses for, but there are a few models that I'll be disappointed to not have still... Nonetheless, it must be done!
    I get very paranoid over hackers and what not since it is so stressful having your stuff get hacked...
    Hopefully everyone updates everything to safetensors (and hopefully safetensors are safe... I feel like if 'safe' is in the name it better be bloody safe...)

  • @jhnflory
    @jhnflory ปีที่แล้ว

    Thanks a lot...I learn so much from your videos

  • @johanngambolputty5351
    @johanngambolputty5351 ปีที่แล้ว +1

    Is this really a danger of "open source", rather than just trusting unverified code? (in which case if its open source, at least its easier to verify?)

  • @lancemarchetti8673
    @lancemarchetti8673 ปีที่แล้ว

    Wow...Bravo man!

  • @sacramentofwilderness6656
    @sacramentofwilderness6656 ปีที่แล้ว

    Wow, never though about this issue! Seems like a good reason to implement __reduce__ method in a way it does some funny (but not harmful) thing like loading funny image on the screen or loud noise)

  • @amitmalaker5445
    @amitmalaker5445 ปีที่แล้ว

    9:44 let me put my two cents on that, I was tinkering with raw CNN code and tensorflow uses hdf5 as a serializable. So, I did a mistake by not taking the input_size of the image in the ConV2D **kwargs. You know what it saved as usual. but when it comes to load_model it gave an error pointing the error specifically for me!! Yeah, hdf5 too evaluates the file while loading!!

  • @droro8197
    @droro8197 ปีที่แล้ว +7

    Some things that can be done is not loading models as administrators and maybe doing it only in contained environments like docker or VMs…

  • @Niohimself
    @Niohimself ปีที่แล้ว

    "I feel like at some point, hugging face is going to be just full of features that they implemented because I did something stupid"
    Hey, I'd take Yannic breaking my code over an actual black hat hacker any day :D

  • @alok9337
    @alok9337 ปีที่แล้ว

    stay on tune with what you want to learn, just because it's hard now, doesn't an it's impossible. It's all about ntal mindset and

  • @winddude9
    @winddude9 ปีที่แล้ว +1

    Very interesting, should have crossed my mind, but didn't!

  • @scottmiller2591
    @scottmiller2591 ปีที่แล้ว

    It's no ";" SQL injection, but it's pretty cool.

  • @abitdisturbedbyitall939
    @abitdisturbedbyitall939 ปีที่แล้ว

    Thank you

  • @IulianArcus
    @IulianArcus ปีที่แล้ว

    This looks like the anti-cheese model of security. Bubble up the warning until someone forgets about it. Instead they should ensure that models are scanned, there is a safe way to use pickle and torch mandates that method.

  • @Veptis
    @Veptis ปีที่แล้ว

    Pressing F12 in VSVode to jump to the definition of some class or function never ends.
    Perhaps use VScode and read the docs to have docs in VScode like the website looks because it's all based on docstrings.
    So it's impossible to rely on the super().__reduce__()?

  • @killroy42
    @killroy42 ปีที่แล้ว +1

    How is there not a way of locking eval and exec down in these environments?!

  • @jagofly1842
    @jagofly1842 ปีที่แล้ว +1

    Is this also an issue when loading .h5 files or only for models saved as .bin?

  • @ChristopherEGr33n33
    @ChristopherEGr33n33 3 หลายเดือนก่อน

    Hey Yannic, I am trying to work on a challenge I believe is based around this video. Is there a way I could share it with you and ask a few question but to see if I am implementing it correctly?

  • @radoslawglebicki1975
    @radoslawglebicki1975 ปีที่แล้ว

    Sounds strange to me place in one sentence: hidden and open source! :-D

  • @bernardoramos9409
    @bernardoramos9409 ปีที่แล้ว

    What is the music at the end?

  • @fizipcfx
    @fizipcfx ปีที่แล้ว +1

    When are you gonna do eye reveal :)

  • @jamilndemele3972
    @jamilndemele3972 ปีที่แล้ว

    Thank you in advance

  • @pappaflammyboi5799
    @pappaflammyboi5799 ปีที่แล้ว

    Is there a way to sandbox pickle initially so as to detect executable code or malware?

  • @tellu5493
    @tellu5493 ปีที่แล้ว +1

    Would virtualization like running off a docker image protect you from this?

    • @skierpage
      @skierpage ปีที่แล้ว

      Any kind of sandboxing limits what arbitrary Python code can access in the local file system; but e.g. the malicious datafile's code could read whatever is in your local data directory and exfiltrate it with network calls.

  • @PixelPulse168
    @PixelPulse168 ปีที่แล้ว

    love your videos

  • @TheRohr
    @TheRohr ปีที่แล้ว

    Thanks for the video. Still, I did not get the point "How the malicious code got onto my computer". So, you save with a "patched version of save", but I still cannot execute it locally or why should python automatically download it; do you point to it via url like in a javascript attack?

  • @MubashirullahD
    @MubashirullahD ปีที่แล้ว

    Usually, making things run on other people's machine is quite hard

  • @benjaming.8368
    @benjaming.8368 ปีที่แล้ว

    Will there be a library to unpickle with reduced administrative rights?

  • @walkingtourhd
    @walkingtourhd ปีที่แล้ว

    Are PyPI, Tensorflow hub, Pytorch hub just as dangerous as HF?

  • @CTimmerman
    @CTimmerman ปีที่แล้ว

    Pickle trick!

  • @paxdriver
    @paxdriver ปีที่แล้ว

    Excellent

  • @snowballsimpson3887
    @snowballsimpson3887 ปีที่แล้ว +1

    This is why we can't have nice things.

  • @kristoferkrus
    @kristoferkrus ปีที่แล้ว

    Do you work at meta? If so, then what is it like working with Yann LeCun?

  • @balooleffe
    @balooleffe ปีที่แล้ว

    thanks bro

  • @arminhejazian5306
    @arminhejazian5306 ปีที่แล้ว

    very interesting

  • @television9233
    @television9233 ปีที่แล้ว

    Great information that everybody should know.
    But why would you make the github project? This would just make the exploit (which I agree is already easy) that much easier to be used. It just invites more people to exploit it and I see no use for the github project.

  • @vadimkantorov
    @vadimkantorov ปีที่แล้ว

    Could also just do eval('__import__("webbrowser")....')

  • @elmichellangelo
    @elmichellangelo ปีที่แล้ว

    Welp hacking people has never been this easy

  • @Henk717
    @Henk717 ปีที่แล้ว

    Turns out, people found solutions for this. Your demonstration now errors out during the load on the United version of KoboldAI (Only takes GPT models, so had to test with a GPT version of your example). Curious if people will be able to bypass it.

    • @sncncd
      @sncncd ปีที่แล้ว

      Hey dude could you give me a bit more details about it? (Working on the Open Assistant project)

    • @jonh2o
      @jonh2o ปีที่แล้ว

      Huh?

  • @LethalBubbles
    @LethalBubbles ปีที่แล้ว

    "open source is dangerous"
    *turns around*
    "here look at the source code and see how dangerous it is"
    😕

  • @talha_anwar
    @talha_anwar ปีที่แล้ว

    me getting feelings of a hacker

  • @UnrebornMortuus
    @UnrebornMortuus ปีที่แล้ว

    Ah yes my friend my fellow awareness giga chad. Once we make everyone aware, one of them will find the solution for us :)

  • @nightwintertooth9502
    @nightwintertooth9502 ปีที่แล้ว

    pandas has a built in json that doesn't have the pickle security holes going on, cmon now.

  • @yoyopro4250
    @yoyopro4250 ปีที่แล้ว

    How is your learning progression? I'm tNice tutorialnking about getting the Signature version soon, people like you are really persuading to give

  • @anon5704
    @anon5704 ปีที่แล้ว

    Does anyone have experience with realESRGAN? It’s a popular image upscaler often used for AI art like Stable Diffusion. It involves a .pth which uses PyTorch and Pickle. I don’t know whether the source is trustworthy and how safe it is to run

  • @HichemFrozenBlood
    @HichemFrozenBlood ปีที่แล้ว +1

    Well there is a thing we can do... don't use pickle ! Any file format that is only used to store data and doesn't contain executable code is fit to solve this security issue.

    • @benjaming.8368
      @benjaming.8368 ปีที่แล้ว

      dont use torch.load?

    • @HichemFrozenBlood
      @HichemFrozenBlood ปีที่แล้ว

      @@benjaming.8368 No, use a different saving protocol instead of pickle (torch.load calls the pickle module by default). Use one that doesn't execute arbitrary code on load.

  • @dabbopabblo
    @dabbopabblo ปีที่แล้ว

    Any low level function with such a non descriptive name such as pickle I'm always weary of.

  • @nightwintertooth9502
    @nightwintertooth9502 ปีที่แล้ว

    pandas has a built in json loader that doesn't have the pickle exploits, cmon now.

  • @mgostIH
    @mgostIH ปีที่แล้ว

    Dynamic typing and its consequences have been a disaster for the human race.

  • @NeoKailthas
    @NeoKailthas ปีที่แล้ว

    You can't run these models on a container can you? Because of the GPU requirements... Well this sucks

  • @search620
    @search620 ปีที่แล้ว

    Malwarebytes and nod 32? not recognize it?

    • @xbon1
      @xbon1 ปีที่แล้ว

      Mbam is weaker than windows defender

    • @search620
      @search620 ปีที่แล้ว

      @@xbon1
      Mbam = malwarebytes?
      what about nod32?

    • @xbon1
      @xbon1 ปีที่แล้ว +2

      @@search620 mbam = malwarebytes yes. Windows Defender beats out everything except BitDefender right now, but BitDefender is only a bit better. AV research tests have shown that all you need nowadays is Windows Defender and common sense for the most part.

  • @itistoday
    @itistoday ปีที่แล้ว

    Maybe they should just not use pickle...?

  • @twobob
    @twobob ปีที่แล้ว

    "Does thinking", whilst this could be used for bad it could be used for good. Sigh. If only people leaned towards 'good' by default.

  • @Sven_Dongle
    @Sven_Dongle ปีที่แล้ว

    Java has a far superior serialization subsystem.

  • @EternalKernel
    @EternalKernel ปีที่แล้ว

    I never liked pickle..

  • @joshuascholar3220
    @joshuascholar3220 ปีที่แล้ว +2

    So now that you've shown the whole world how to upload malware to hugging-face, do you think you can do enough good improving security as the harm you've done, releasing this code that helps anyone upload any malware they like with zero understanding or effort?

    • @PeterSeres
      @PeterSeres ปีที่แล้ว +3

      Wow I think you took away exactly the opposite of what he was trying to explain.
      The only reason to prevent misuse is by spreading awareness. If you don't talk about vulnerabilities then they will fly under the hood for a longer period of time and more people will fall victim to truly malicious code.
      I very much doubt that anyone with serious malicious intent would use his awareness-spreading repository. They would instead write something that's much better concealed and hidden but exploits the same vulnerabilities presented here.

    • @joshuascholar3220
      @joshuascholar3220 ปีที่แล้ว

      @@PeterSeres nonsense. No one reads through the code when they download from hugging-face. Any exploit is as hidden as any other.

    • @Kai-K
      @Kai-K ปีที่แล้ว

      Security through obscurity is no security at all. If you think threat actors weren't already looking at this vector before he shared this, I don't know what to say to you.
      Not reporting problems because you're scared of malicious people is how you get endemic vulnerabilities that are exploited for many years, sometimes even decades. It was responsible to spread awareness, and by construing it as "[doing] harm", the narrative presented is the same one people who don't want vulnerabilities patched use.

    • @joshuascholar3220
      @joshuascholar3220 ปีที่แล้ว

      @@Kai-K no one forced him to release his code to the public, but he did!
      And since hugging face would have to replace an entire module to fix this, they probably won't.
      So now explain to me how we're safer.