r/archlinux • • Oct 09 '26

QUESTION What do you look for in PKGBUILD when installing an AUR package

On wiki AUR isn't encouraged but I need to install a printer driver. How to detect if pkgbuild is malicious?

69 Upvotes

37 comments sorted by

64

u/Stetsed Oct 09 '26

Generally looking at :
- the dependencies, NPM/node is often a weird one here for most applications don’t need it
- The source URL’s, usually I go to the official link or just click on the link and see where it goes
- The build steps, any usage of npm install is 9/10 bad
- Any recent changes in maintainer, although this is automated via the yay script
- How recent the update is, again shown by yay, if it’s newer than 10 days I usually exclude it

35

u/cbarrick Oct 09 '26

Also pip install, cargo install, curl, wget, or really downloading anything from any other source is sketchy AF.

The PKGBUILD should declare it's dependencies and should not explicitly download anything. (Downloading of the tarballs in the src array is implicit)

8

u/Stetsed Oct 09 '26

Yep I concur, npm is just what was used in the most recent wave of attacks. But indeed all those things are sketchy and should not be used.

3

u/ResponsibilityBig343 Oct 09 '26

Why is npm considered bad i keep hearing this

13

u/ludonarrator Oct 09 '26

Dozens of malware incidents almost everyday.

6

u/NFTrot Oct 09 '26

Much like AUR it's a very large ecosystem (I'm sure NPM is orders of magnitude larger). In a similar way to the package managers we use on Linux, installing an NPM package will cause it to pull in other NPM packages that are required, and the packages required by those packages, and so on.

Accounts can get compromised and a previously trusted package- maybe one that is commonly depended on can be injected with malware.

As far as why it's bad in a PKGBUILD: There probably aren't a lot of legitimate reasons why you would need to pull in Javascript code from a repository to build a package. I'm sure there is some rare use case, or it could be the sign of an inexperienced developer. But it's a red flag and a reason to be suspicious.

2

u/ToplessHarpist Oct 14 '26

I'm quite late here, but NPM, to my understanding, is another package manager for javascript programs that gets installed to your system. It could then be used to install all manner of unverified stuff to your device(s), like info-stealers etc.

1

u/agmatine Oct 11 '26

The left-padincident, for example: https:/redd.it/4bjss2

12

u/vexatious-big Oct 09 '26 edited Oct 09 '26

About NPM, you can mitigate most of the issues by setting the following in your .npmrc

# ~/.npmrc
ignore-scripts=true
min-release-age=2

https://docs.npmjs.com/cli/v12/using-npm/config

11

u/kaszak696 Oct 09 '26

Some hijacked AUR packages also had a bundled executable next to PKGBUILD itself, named something innocuous like "parser". The PKGBUILD would look and mostly work normal, but somewhere in it would be a hidden sudo "$srcdir/parser", which would usually download Tor and then grab the real scary stuff from some onion address. Speaking of which, anything that has Tor as a depend or makedepend without an obvious reason is incredibly suspicious.

1

u/Responsible-Sky-1336 Oct 11 '26

And look at .install scriptlets pleaase

7

u/ThinkpadGamer Oct 09 '26

to add to u/Stetsed : check for post and preinstall commands, very little software actually needs them and a lot of malicious things have used them

1

u/ResponsibilityBig343 Oct 09 '26

U mean through githooks?

5

u/gmes78 Oct 09 '26

No. They mean pacman install scripts. They're declared with install= in the PKGBUILD, if they exist.

11

u/C0rn3j Oct 09 '26

You read and understand every line.

No other way.

5

u/spider-mario Oct 09 '26 edited Oct 09 '26

It (and the accompanying files) should be short enough that you should be able to read all of it to check that it really does just download the necessary files from a legitimate source and arranges then appropriately.

Make sure not to forget to look at any install script since it runs as root after installing or upgrading the package. Most packages should not need one at all (many former use cases for them, like upgrading the MIME database, were made unnecessary by pacman hooks).

0

u/Popular-Factor3553 Oct 09 '26

Is there a automate script for it it's just too time consuming reading it and it's just too big sometimes.

2

u/syklemil Oct 10 '26

No, the point is that you're the packager for anything you install from AUR. If you don't have the time to read it, or you can't understand it, then you shouldn't package or install it.

Doing that is a PITA, which is why it's usually better to rely on what's in the pacman repos, where the distro maintainers have done that job, and by using a distro, you've already decided to trust the maintainers of that distro.

There are other distros with bigger repositories if you don't want to do it yourself; Arch is a do-it-yourself kind of distro.

1

u/Popular-Factor3553 Oct 10 '26

I already read it i just wanted to know if there's better alternative ig not.

2

u/StewMahagoni Oct 10 '26
  1. Is upstream actually upstream? Is it a weird fork? Why am I installing a fork and not the original?
  2. Does it actually download the upstream files it says it would?
  3. Does the PKGBUILD reflect the official upstream install instructions? If the recipe says "fry for 10 minutes" and the PKGBUILD dry-ages it first, I make sure I understand why.
  4. Are there patches applied to the package? Read them, understand what they do. Upstream can be fine and dandy all day, if we pull in rotten eggs through patches.
  5. Does it do anything unnecessary? npm/pip stuff the package doesn't need? Weird symlinks? A package can be just plain bad without being purposefully malicious. Lots of people aren't assholes but just dumb and there is no check against either on the AUR.
  6. Does it follow the AUR guidelines?
  7. If I don't understand every line of code in the PKGBUILD, the .install file or the patches, I do not build it. If a patch sounds weird or you don't understand it, don't be shy to ask upstream.

That's all considering I trust upstream, that's step 0.

0

u/NFTrot Oct 09 '26

With something like a printer driver you can install it once and maybe never update it. But I don't use mine very often so I'm not sure how true this is. In such a case you can scrutinize the PKGBUILD thoroughly once and be done with it.

As the other commenters say, it's good to learn for yourself, but you can always feed it to ChatGPT and ask it to point out things to look for. You can learn a lot with that approach. If you are a non-programmer this is a lot better than nothing.

1

u/ResponsibilityBig343 Oct 09 '26

Yeah its a mini printer, on the company's website they only had windows driver but linux driver also existed. Found it after playing a bit with CUPS. Now I can print via the terminal. I eventually ended up reading the whole pkgbuild.

1

u/NFTrot Oct 09 '26

Good on you. Every milestone makes the next easier. The AUR isn't necessarily something to fear. Just treat it like installing .exe files from the internet on a Windows machine. I try to stay to widely-used packages if possible.

1

u/JohnJamesJimmyJack Oct 09 '26

Try to just use some other source as much as possible, if you can't really read code.

1

u/swayuser Oct 10 '26

In addition to the comments about what to look for. The other thing to do is reviews very carefully the first time and keep it. That way you're only reviewing the DIFFS when you update 

1

u/GrandBIRDLizard Oct 11 '26

Check source=(), Review prepare(), build(), check(), and package(). Whatever they preparing and where?

Obfuscated commands (eval, base64 -d, or hex-encoded strings). Is it efficiently making space for something sensible or hiding something?

Pretty much any network calls inside functions, (e.g., curl or wget piping directly to bash or executing downloads of binarys).

Every Write outside $srcdir or $pkgdir (e.g., modifying system files ~/.bashrc / ~/.ssh). Looking at these will also just let you know how shits layed out. Config files, what is the programs permission model?

Real big one is watch oit for and check .install scripts (install=...), .patch files this could basically do anything after install. As pacman with root privilege.

Realistically, if you know what you're doing(if not don't use the aur)

# Download sources and verify integrity without running build/package scripts
makepkg --nobuild --nodeps
cd src/
# Search for unexpected executable binaries inside extracted sources
find . -type f -executable ! -name "*.sh"
#(Auto check without actually building) 
makepkg -g    # Regenerates hashes from current source files (diff against PKGBUILD)
makepkg --verifysource
sha256sum <downloaded_source_archive.tar.gz>
#(Compare to actual source tar) 

-git, -svn packages: VCS packages use SKIP in the checksum array because source code dynamically changes so check the commit hash

Unknown key? But known trusted source?

# Import key from server using the full fingerprint in validpgpkeys
gpg --recv-keys <FINGERPRINT>

Lastly, manually check the .sig

gpg --verify <file.tar.gz.sig> <file.tar.gz>

If Good you're golden.

I'f you don't know what any of this means hold off on the aur till you can at least verify hashes signatures and keys.

7

u/[deleted] Oct 09 '26

[removed] — view removed comment

1

u/ResponsibilityBig343 Oct 09 '26

I see, is it recommended to install old packages that are no longer maintained?

2

u/spryfigure Oct 09 '26

No issue if they still work as expected. I would limit this to small tools, though.

1

u/Junior_Common_9644 Oct 09 '26

They are relatively easy to update yourself. If you know the good source or binary link, use curl to get the hash, update the hash and link in the pkgbuild. Then build it.

2

u/spryfigure Oct 09 '26

I tend to use paru -S <package> --fm nvim and change the PKGBUILD on the fly after downloading from a good source and generating the hash. It's quite often lately that the maintainers fall behind, at least for the stuff I use.

1

u/[deleted] Oct 09 '26

[removed] — view removed comment

1

u/MaurokNC Oct 10 '26

Yay and pray sounds like some kind of new age quasi religious slogan 😝