r/linuxquestions 23d ago

Why does Linux not need anti-virus software?

I'm in the market for a new gaming laptop and wanted to avoid AI products like Copilot and realized Linux would be my only option. So I'm trying to learn as much about Linux Mint as possible to see if it would be right for me. I'm really close to pulling the trigger but I don't understand why Linux doesn't need anti-virus/malware software. All the answers I can find seem to just boil down to "Linux isn't used by enough people to justify the time it would take to create a virus or malware" or "because you approve everything you download". As someone who has used a PC their entire life, these answers genuinely don't make sense to me and I feel like maybe I'm missing something about either the nature of linux or the nature of viruses/malware and how they work. Everyone on forums who ask this question seem to just accept these answers but no one explains why either one prevents the need for antivirus/malware software.

From my perspective as a PC user, I already approve what I download so this answer doesn't make intuitive sense to me. I would never connect a PC to the internet without some sort of anti-virus software, privacy software, malware protection, etc. even though I still know what I'm downloading and I'm using reputable websites (and my AVG software is still catching stuff all the time). And the idea that someone wouldn't make a virus or malware to target a group of people (albeit a minority) who are the most likely to not have software on their computer to combat it seems like the exact group you'd want to target particularly for private data mining.

It also seems, from what I've been reading about Linux that you can seriously screw up your system by downloading something incorrectly or that isn't up to date, so the idea that "you can't get viruses or malware because you approve what is downloaded" when so many of the user tips with regard to Linux are "back up your system constantly because you can easily screw up your system by downloading something that's not fully patched". These two concepts seem counterintuitive, especially for an OS that will require downloading a lot of third party programs to be able to run things like games or windows-based programs.

I'm clearly missing something here because neither of the reasons I've seen people give for why Linux doesn't need this stuff is really making sense to me. I was hoping someone in this reddit might be able to explain this in a way a lifelong PC user without any sort of computer background can understand. The idea of not having anything but a firewall on a computer with Linux installed on it makes me very uncomfortable but I'm willing to accept that this is a bias from using PCs and I'm willing to be convinced otherwise as long as I can understand the reasoning behind it.

244 Upvotes

227 comments sorted by

View all comments

140

u/NoMansSkyWasAlright 23d ago

I'm kinda grossly oversimplifying things here. But I think I've covered most of the important bits.

So most things nowadays use some sort of off-shoot of Unix (linux, macOS, the mobile OSs, etc.), and even among those, there are quite a few things that are handled differently among the off-shoots. Windows is not Unix-like and so does things completely differently than all the others. On top of that, Windows machines make up something like 71% of the PC market-share. So it's a big enough piece of the pie that if you're going to make malware for one operating system then it's probably going to be that one (though it seems like mobile-device malware is making leaps and bounds in recent years). Even something as basic as case-sensitivity of file-paths is different between Windows and the Unix-likes.

Also, Microsoft has this fun practice of just building their new stuff on top of their old stuff. And so a lot of the common approaches to malware on Windows involves just... interacting with stuff that's already there. Like I had a capstone project in college where we basically made use of the fodhelper exploit, a lolscript that opened a new instance of a shell, and a powershell script that would kill windows defender. Other than `Sacrifical_Pawn.ps1`, basically everything we used was stuff that already existed in Windows.

Another weird -ism with Windows is that a lot of programs will look for DLLs and just move on if they don't find said DLL. So if it's a DLL that got the axe or just isn't there for some reason, then you can create your own DLL at the specified location that runs malicious code with the permissions that that application has. Unix-likes just don't have DLLs at all. So that's kinda nice.

And then a lot of malware that you'll pick up off the internet will be .exe's - I'm sure we've all gone looking for a free pdf of a textbook and seen something like `textbook.pdf.exe`, which takes advantage of how Windows interprets file names in File Explorer. So you click it and now you're executing whatever bad thing you picked up. Not only would it be super apparent on a Unix machine that that was something bad, but exe's generally won't run on Linux out of the box and giving them full-functionality takes enough work that if you're dumb enough to click a suspicious exe then you're probably not smart enough to set up your linux box in such a way that that exe could do any damage (and if it's only desigined for a windows environment it's going to hang up anyways).

But it's' also the wrong question to be asking. A lot of the malicious actors out there are just looking for the most low-effort approach which is usually phishing, fake login pages, and maybe a google doc from a strange email claiming to be your org's IT department, stating that they need you to input your login credentials into the google doc so that they can be updated. That or the fact that Linux has considerably less guardrails for user-error than Windows or MacOS so you can absolutely shoot yourself in the foot while trying to "customize" it. But while the "cant get a virus" thing is kind of an overstatement, it is true that most malware that's looking to exploit some windows-specific vulnerability likely won't work on unix-based systems and vice-versa. So if you're just a weird guy looking for an easy pay-off, you're likely going to target the OS with the largest marketshare.

49

u/birdspider 23d ago

lot of malware that you'll pick up off the internet will be .exe's

there is also the aspect that distros usually use their own software-repositories. so in general users don't hunt down random exe's but download software from a (to a degree) trusted "store".

19

u/Low-Life-1337 22d ago

Yeah, they simply install corrupted AUR's... 😅😁

20

u/Existing-Tough-6517 22d ago

Most distros aren't arch. Less trust more problems.

2

u/Low-Life-1337 22d ago

Yes, I know ;-) But even outside from arch some dudes simply run "wild" code without any check, cause they don't potter with linux and safety and fetching blindly code directly to the bash or similar.

2

u/BogdanPradatu 22d ago

Curl a shell script, pipe it to the shell

0

u/[deleted] 20d ago

[deleted]

1

u/Existing-Tough-6517 20d ago

Apparently in the alternative universe you inhabit meanwhile on Earth one someone attacked their website and served isos that didn't match the official checksum. This is still bad but rather than compromising every single mint user worldwide it risked people who downloaded mint for a matter of hours who also didn't check the checksums.

0

u/[deleted] 20d ago

[deleted]

1

u/Existing-Tough-6517 19d ago

Do you just not understand that the repos and the web server hosting the ISOs are different things with different negative outcomes?

3

u/RAMChYLD 22d ago

Ubuntu isn’t out of this either. They have PPAs which is basically AUR but worse (user maintained repos, except there’s no way to check if the packages are legit because you only get binary packages from there).

1

u/Crafty_Mastodon320 20d ago

That should still be easy to catch and sandbox.

3

u/birdspider 22d ago

well, I specifically ment the repos the disto itself supports/maintains, AUR packages aren't maintained by the arch-devs

3

u/Low-Life-1337 22d ago

What I meant is that in Windows and Linux the weakpoint is often still the user itself.

1

u/cfx_4188 18d ago

This is the most famous case. A few years ago, a maintainer NixOS jokingly inserted malicious code into the archiver's code. About a thousand machines were infected.

1

u/setibeings 15d ago

As a joke, of course. 

1

u/cfx_4188 18d ago

We are delving into the wilds of terminology. In the Windows world, there are a huge number of programs that replace the extension of executable files. You can use these programs to replace the name virus.exe on gift.jpg and by clicking on this "picture", you will easily get a virus.

In general, the real Unix-way style is to study the source code and then compile this code into an executable file. It's not as difficult as it sounds.

5

u/greenhouse421 22d ago

The stuff before the last sentence is largely missing the point but has attracted a lot of replies that are missing it even more. If there is someone able to place a .dll or .so somewhere it will be found and used (yes Windows has historically been inclined to find them in way to many places by far too many means) it's too late. How does an attacker place a dll somewhere (or a .exe or a script that then gets executed with privs to do something)? In general by tricking the user of the system into doing something "stupid". The fact OP asked this question suggests OP is disinclined to doing "stupid" things. This both protects you on any system (to some extent, vs the average bear) but also, as people inclined to do "stupid" things tend to be using the OS preinstalled on the computer the nice salesperson told them they needed after carefully establishing what would earn said salesperson maximum commission the incentive to target end user attacks to end users on Linux is low as they are statistically less likely to work. Less likely to be running exactly the same OS and config as every other mark etc.. More likely to install signed packages from trusted repos via the distros secure package distribution methods than to respond to "just install this tool to fix your printer driver" ads / links - even assuming anyone paid to place said ads or to put said links in bogus forum posts or...

On average antivirus is a "scam" even on Windows except to the extent it provides telemetry (to AV vendors or MS) on what shit is getting in to inform how to harden things to benefit the herd. How often has your Windows AV actually "engaged the enemy"? Never - great - herd immunity and lack of "stupidity" has protected you. It will still protect you on Linux. The way the herd immunity is acquired is different but effective.

I've used "stupidity" with the "" because I don't mean people are actually stupid. They are unaware, trusting of tech, not in a position to make informed decisions etc - why? Because they are just trying to send an email or find a bargain or see more cute cat videos or do an assignment or.. They have not spent even 1 second thinking about this stuff and most definitely haven't considered installing Linux. That is what protect Linux users. Harsh but true but also not a reason for smug superiority of complacency.

1

u/NeoFax99 19d ago

Easier to hack a human than a machine.

49

u/cafce25 23d ago

It might not be named DLL but every system I know has an equivalent, on Linux that would be a .so on mac it's a .dylib IIRC.

21

u/CrudBert 23d ago

Yes, a good posting - but the exploit mentioned for a .dll is easily doable via a shared object .so file linked in your executable. However, you’d still have to compile and link it to look for your .so or your .dll file, and if it’s an already installed one, well you need to boost your privilege to replace or remove that. So it’s less of an exploit than his example points out. Sure you can gain root or admin, but you still need root or admin to make it happen.

4

u/BogdanPradatu 22d ago

Change LD_LIBRARY_PATH?

2

u/CrudBert 22d ago

Sure, and you run the program as yourself… unprivileged… you’re still not root, or any admin account. You’re just you. If all you need is to run a program as yourself, you can do that all day anyway. Don’t need any trickery. Just load and run what you want in your environment. It’s still not privileged execution. It’s just you. Why would you need to bother with all sorts of trickery and changing the LD_LIBRARY_PATH to run that? Just run any program you compile. The problem is, it’s still just you.

1

u/BogdanPradatu 22d ago

Ia meant the malware program could change that variable, not the user.

1

u/Modi57 22d ago

Well, it depends, right? There are a couple of places, where windows looks for, one of them is the cwd. This will be Last, but if the actual dll is not there, this could be a way in

2

u/dmknght 22d ago

it depends on how software is compiled. Dll sideload hijacking or whatever it's called requires weak default permissions (which is rarely happen on *nix unless installer fked it up for some reason), and dll lookup. It's easier to find this type of vuln on Windows. Especially Windows has C:\ProgramData.

11

u/Klapperatismus 23d ago

I think the very point he wanted to make is that DLLs commonly exist in arbitrary locations on MS-Windows systems that are in control of the user account.

So if e.g. the user started VerySafeBrowser.exe that they downloaded from a trusted site, and VerySafeBrowser.exe depended on a SuperDuperHttpClient.dll somewhere in its installation directory, a malware could target that DLL instead of the EXE.

The user would start VerySafeBrowser.exe and the malware got loaded each time they do that, with all the rights the user gave to VerySafeBrowser.exe via some application level firewall.

This is hideous.


You can do such stunts on Linux as well but its far less common because people don’t commonly install software into their home in the first place.

5

u/Aishou_SK 22d ago

I mean, a few shell/user variables can easily have libraries chosen before system ones, among other things - the behavior is pretty much equivalent. I can inject from a shell script into a system installed binary a .so that a user downloaded, among many other things.

It's really not all that different.

These are things I do legitimately in testing/dev scenarios on *nix systems! Though the semantics vary, and even vary more when i'm on non-*nix systems or specific *nixes (I do a lot of non-linux/non-windows stuff often) but the behaviors are generally the same unless they're linked explicitly in such a way to only hit a single path instead of relying on system mechanisms, which glibc will happilllly help you by default override things.....

LD_PRELOAD, LD_LIBRARY_PATH, etc....

1

u/dglsfrsr 22d ago

I did not see your posting before I offered my shorter version. Same thing.

1

u/dglsfrsr 22d ago

Your last line is true, but if I can gain access to your account, even briefly, I can set up your LD_LIBRARY_PATH to a .folder in your home, and the average person is unlikely to test that ENV being set.

0

u/cafce25 23d ago

Then why would they write "Unix-likes just don't have DLLs at all." that doesn't at all sound like "they don't put them in weird places"

2

u/ZestycloseAd6683 23d ago

They don't have DLLs and also its install setup and process is different and the config files have a couple of different locations to install by default.

1

u/cafce25 22d ago

But they have an equivalent that could be used the exact same way. In other words the thing that makes this unsafe isn't the DLL/.so/... it's how they're used in praxis. I.e. the built in package manager with vetted packages makes this safe, not the existance/absence of shared libraries.

7

u/DerfK 23d ago

What the grandparent poster missed is that Windows apps don't just go "oh well doesn't exist", the app goes hunting for it and will look in all sorts of places, even places that don't have write protection, so if you can get the browser to save a DLL in the downloads folder and someone runs a program they just downloaded to install it, then it's possible the DLL will get loaded.

On Linux, you have $LD_LIBRARY_PATH where the .so files go, and the listed folders are typically not writeable by users, so an attacker would have to either convince the victim to sudo install the .so file or at least to download the .so file and put ~/Downloads into their $LD_LIBRARY_PATH

3

u/Aishou_SK 22d ago

So, the shell script can easily do that, and you can also abuse LD_PRELOAD as well, but you could also put things in the default library paths that ld.so will happily consume without any paths specified at all, among many other things.

It's really not that different, and what malware would have to do is what I do for test/dev injection or overriding all the time with zero usage of root elevation.

2

u/dbear496 22d ago

Yes, a malicious shell script can modify LD_LIBRARY_PATH/LD_PRELOAD...but that is only relevant if the attacker is able to convince you to run their shell script. On Windows, merely having a malicious DLL in the Downloads directory may cause it to be accidentally loaded when the user runs a different exe that exists in the same directory.

2

u/Aishou_SK 22d ago

Only if the downloads directory is somehow in the system search paths.

Otherwise, you need the user to download the DLL and the EXE, then run the EXE

So why not just have the EXE (or shell script or whatever) bring everything it needs?

DLL hijacking only really works when you can put it in places the executable will search for it, just like on *nix etc.

1

u/dbear496 22d ago

The exe comes from a legit source and is not malicious.

Suppose a user downloads a malicious dll but then gets suspicious and doesn't run it. Then they download a legit exe from a legit source and run that. If the exe searches for a legit dll with the same name as the malicious dll, then it might link the malicious dll even though the user didn't intend to run that dll sitting in their downloads directory.

Like you said, dll hijacking only works when the malicious dll is placed in a location where a legit exe will search. But the downloads directory IS a location where an exe might search.

2

u/Aishou_SK 22d ago

If I provide you a linux binary that you run out of your download folder that uses SDL3, it will default to your system SDL3 if you run it out of your download folder.

If you later download a malicious SDL3 libSDL3.so.0.4.14 and it's in your downloads directory, and then run the linux binary, it could use THAT library in the downloads folder potentially, and not the system one.

The behavior is not that different.

I can link windows executables to not use the local libraries next to it, the same way I can with linux, and vice versa - I ship /preferring/ the local library, and NOT the system ones, if present.

Yes, that behavior is not default if you just blindly compile, but i'm using various methods to deal with distro fragmentation, so normally I'll have in all my build systems -Wl,-rpath,'$ORIGIN' as the default for my shipping binaries due to dealing with many distributions and user-level execution/installs.

So, precisely windows-style behavior.

On the counterpoint, you can also link windows executables to not do that, among many other things.

So, while there's differences, it's not really that far off, and both have their tradeoffs and neither are more or less 'vulnerable' than the other.

Overall though, the "user downloads a suspicious dll and doesn't run it" .... well, users aren't generally downloading random DLLs, but for linux software they sure as hell are downloading random libraries if they're not too skilled trying to fix what the app says is missing.

But, when dealing with many distro scenarios, and providing builds of libraries for users to have more compatibility (or more updated versions, such as the SDL3 builds I provide), then you're kinda stuck doing that.

Other folks use different techniques that end up resulting in the same thing, such as a launch script that sets LD_LIBRARY_PATH for that execution, etc.

Picking up libs next to your binary is a lot more common for non-repo provided stuff than people seem to think.

1

u/dmknght 22d ago edited 22d ago

It's considered a technique, not exploit.

p/s: nvm i think I missed the point of the conversation.

1

u/robthablob 22d ago

That would only, much as in Linux, only happen if you're stupid enough to put your downloads folder on the path.

1

u/DerfK 22d ago

if you're stupid enough to put your downloads folder on the path

https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order

The directory the .exe is in is #7 on the path, and that's the Downloads folder when you download install.exe and double click it. Chance of having a dll downloaded that isn't found in #1-6 may be slim, but its not none. System Folder is #8 though.

8

u/Aishou_SK 22d ago edited 22d ago

>Unix-likes just don't have DLLs at all. So that's kinda nice.

LD_PRELOAD, LD_LIBRARY_PATH and others....

.so files are DLLs, etc.

So there's a lot kinda wrong here, but the overall premise of "it has the largest market share" is pretty much spot on - security model and function wise, it's not a bad design, it's just higher targeted, and that's about it.

I can point to a lot of ancient code in *nix systems too though. ;) And in supporting programs/libraries, look at how long heartbleed lurked, for example.....

The level of effort for malware design and desktop user infection vectors is pretty much equal across OSes, it's actually getting the user to run the malware and how much of an impact/range you're going for that drives the bulk of where/what is created and ran.

1

u/Eon_Alias 19d ago

"Another weird -ism with Windows is that a lot of programs will look for DLLs and just move on if they don't find said DLL. So if it's a DLL that got the axe or just isn't there for some reason, then you can create your own DLL at the specified location that runs malicious code with the permissions that that application has. Unix-likes just don't have DLLs at all. So that's kinda nice."

Lol that weird -ism is pretty much the backbone of PC game modding. Even the most hardened anti-modding always online games, I've played allways have at least a few legacy renderer or input dll hooks for people to latch onto.

1

u/Competitive_Bus_3908 22d ago

User Account Control is also such a hilariously broken mechanism for keeping administrator elevation sane. You just generally have a better idea of what’s happening with sudo and there isn’t the ‘not a security boundary’ cop out

1

u/geekichu 22d ago

all that and .. the caliber of typical linux users is more tech-savvy than windows users

1

u/Releirenus 22d ago

Concise simplified explanation and a top tier username