News for hackers. Stuff that matters.
Re:Rust Without Crates.io by tikkabhuna on Tuesday November 14, 2023 @06:15AM (#38261835)
> If crates.io goes down or access is otherwise disrupted then the Rust community will stop work.

As someone who has worked in a big corporate their entire career this statement is bizarre. This has been solved for Java for over a decade.

Builds don't access the internet directly. You host a proxy on-premise (Nexus/Artifactory/etc) and access that. If the internet location is down, you continue as normal.

> You need only one author in your maybe-hundreds-of-dependencies tree to be hacked, coerced or in a malicious mood for you to have a really bad day.

There are products (Nexus Firewall) that can check dependencies for vulnerabilities and either block them from entering the network or fail CI pipelines.

Re:Rust Without Crates.io by brabel on Tuesday November 14, 2023 @06:26AM (#38261933)
The main problem the author is talking about is actually about version updates, which in Maven as well as crates.io is up to each lib's author, and is not curated in any way.

There's no technical solution to that, really. Do you think Nexus Firewall can pick up every exploit, or even most? How confident of that are you, and what data do you have to back that up? I don't have any myself, but would not be surprised at all if "hackers" can easily work around their scanning.

However, I don't have a better approach than using scanning tools like Nexus, or as the author proposes, use a curated library repository like Debian is doing (which hopefully gets enough eyeballs to remain secure) or the https://github.com/crev-dev/cargo-crev project (manually reviewed code) also mentioned. It's interesting that they mention C/C++ just rely on distros providing dynamic libs instead which means you don't even control your dependencies versions, some distro does (how reliable is the distro?)... I wonder if that could work for other languages or if it's just as painful as it looks in the C world.

Re:Rust Without Crates.io by jjgreen on Tuesday November 14, 2023 @06:40AM (#38262059)
Coding mainly in C for 20 years, I've never had a program break on minor version of system shared library conflict. Occasionally need to recompile on OS version update when the major version increments.
Re:Rust Without Crates.io by goodpoint on Tuesday November 14, 2023 @07:16AM (#38262351)
That does not solve supply chain attacks.
Re:Rust Without Crates.io by mid-kid on Tuesday November 14, 2023 @07:31AM (#38262508)
It solves most supply chain attacks. Distro maintainers are users, not developers. They put the needs of a user first, and their work is reviewed during submission. If one of them goes rogue, the damage is usually caught before reaching the user and otherwise minimal, as the update is simply reverted by other maintainers and a different maintainer can take over their packages.
Re:Rust Without Crates.io by goodpoint on Tuesday November 14, 2023 @09:24AM (#38263623)
Sorry, I misread jjgreen's comment. I 100% agree with what you are saying.
Re:Rust Without Crates.io by lmm on Tuesday November 14, 2023 @09:44PM (#38272712)
The C community basically doesn't bother with libraries. They're so cumbersome to do in C that you'll tend to only have, like, 20 giant libraries in your (non-vendored) dependencies.
Re:Rust Without Crates.io by mid-kid on Tuesday November 14, 2023 @07:28AM (#38262478)
It works in the C world because everyone is super fixated on library compatibility, and the programs are expected to be rebuilt by the distribution when necessary. When an API is broken, this entails a new major version and installing both versions side by side until all maintained software is ported. This doesn't happen often enough to be an issue - that's the perk of having a really mature ecosystem.
Re:Rust Without Crates.io by Aerbil313 on Tuesday November 14, 2023 @11:11AM (#38265137)
On the other hand, having tasted Nix, the process you are describing seems as backwards and archaic as operating punched card computers to me. So much wasted human time, serving a need (of an ecosystem) now obsolete, thanks to Nix.
Re:Rust Without Crates.io by brabel on Tuesday November 14, 2023 @12:22PM (#38266326)
I'm trying to use Guix (just prefer it due to the language, Guile, over Nix) but unfortunately it doesn't have a lot of software packaged yet. I tried to build a project I have but it doesn't even have a "builder" for the language I used , Dart (which compiles to binary on all OSs), and I can't find out how to create a "builder" for it... someone did this for Nix to build pub packages so it's possible, but it seems if you want to use Nix/Guix you're stuck on a very limited set of things you can use? Is that a fair analysis? Do you have hints to build your own software when it's not available on Nix/Guix?
Re:Rust Without Crates.io by Aerbil313 on Tuesday November 14, 2023 @02:19PM (#38268136)
Re:Rust Without Crates.io by dannymi on Tuesday November 14, 2023 @05:16PM (#38270592)
In general adding a build system to Guix works like this:

1. Git clone https://git.savannah.gnu.org/git/guix.git

2. Nicolò Balzarotti already has a work in progress patchset adding Dart itself--see https://issues.guix.gnu.org/44926 . Patch your guix checkout with the files you can download on that page via the downarrow buttons on the right.

3. Create a file guix/build-system/dart.scm (I'd copy it from guix/build-system/dub.scm and then s/dub/dart/g and s/ldc/dartcc/g) or whatever it is. This file is the "front end" and is support for dart for the guix package manager script.

4. Create a file guix/build/dart-build-system.scm (I'd copy it from guix/build/dub-build-system.scm and then s/dub/dart/g). This file is the "back end" and is responsible for the build of your package inside a new container.

5. Add references to your new files to gnu/local.mk

6. In your user package script (whatever you want to compile in dart), add #:use-module (guix build-system dart) near the top and then add (build-system dart-build-system) to your package.

7. guix environment --pure guix

8. ./bootstrap

9. ./configure --localstatedir=/var

10. make -j5

11. exit

12. ./pre-inst-env guix build -f yourpackage.scm or whatever

13. Fiddle with the "invoke" parts in guix/build/dart-build-system.scm until your user package works.

14. Submit your results to [email protected] or [email protected] (no need to be subscribed).

As you can see, adding a new programming environment is quite some work. Because every programming environment has its own idiosyncracies, I don't think it can be avoided even in principle.

Re:Rust Without Crates.io by brabel on Wednesday November 15, 2023 @02:32AM (#38274208)
Thanks for the detailed information. Looks like it's a huge effort. That Pull Request is adding Dart 2.8 while the current version is 3.1.5 (and it's released often, at least once a month). Most pub packages don't even work on Dart 2.x anymore. An unrelated question: what do you mean by my "guix checkout"? I saw this in some docs (to add guile-guix to the guile load path so emacs can help me write guix code) and I don't know where that is as I am using Guix OS (in a VM) and as far as I know there's no sources in it?
Re:Rust Without Crates.io by dannymi on Thursday November 16, 2023 @12:46PM (#38292820)
>what do you mean by my "guix checkout"

I mean the working copy (the local directory) created by git clone.

>Looks like it's a huge effort.

Probably.

I've never used Dart in my life, so I don't have so much Dart-specific information, sorry.

> That Pull Request is adding Dart 2.8 while the current version is 3.1.5 (and it's released often, at least once a month). Most pub packages don't even work on Dart 2.x anymore.

Then as a next step you (or someone) would probably add another dart package for version 3, building it with Dart version 2 (is that how the dart build works? Probably).

>as I am using Guix OS (in a VM) and as far as I know there's no sources in it?

Just do the git clone. The guix package manager is a regular program (with source on git) like any other.

I always use a git clone of the guix master branch (for like 6 years now) and it was never a problem. But if you instead want to use the version used by your OS, do guix build -S guix . It will unpack the source of the current guix and tell you where it is. I wouldn't bother doing the latter though.

Also, basically there's a guix daemon that does the build container management (think of it as something like dockerd) and then there's the guix frontend. I'd never do "make install" in the guix working copy--so the guix daemon will not be fucked with. The ./pre-inst-env allows you to run the local directory guix frontend without installing it.

Re:Rust Without Crates.io by oblio on Tuesday November 14, 2023 @07:54AM (#38262704)
Everyone is focusing on Nexus Firewall. Nexus/Artifactory themselves are private repos/proxies/caches that are in widespread use in the Java world so up to a point most companies prune their own repos.

This is NOT standard practice in the JS/Python/PHP/whatever world because these products do not exist or are not widely available, everyone "drinks" directly from the open internet source.

Yes, again, solutions exist, technically, but how many companies do you know, especially smaller ones, that do this?

For Java almost every company bigger than 5 devs tends to set up their own Maven repo at some point, many do it on day 1 because at least 1 dev is familiar with this practice from their former BigCo and it's easy to set up Nexus/Artifactory.

Re:Rust Without Crates.io by claudex on Tuesday November 14, 2023 @09:05AM (#38263402)
Artifactory works well with as a proxy for pip for Python
Re:Rust Without Crates.io by oblio on Tuesday November 14, 2023 @09:06AM (#38263425)
Yeah, I know that these days they can do everything, but the cultural bias is there.

The average Java dev will try to reach for Artifactory/Nexus much sooner than the average Python/Ruby/PHP/Javascript/... dev, in my experience.

Re:Rust Without Crates.io by pjmlp on Tuesday November 14, 2023 @12:56PM (#38266891)
Only because of company culture, in most enterprise projects I work on, doesn't matter the stack, everything gets legal and IT approvement into the internal Nexus.

Devs might do whatever they feel locally, however if those files are going through CI/CD their dependencies better be in Nexus.

Re:Rust Without Crates.io by TeeMassive on Tuesday November 14, 2023 @07:06PM (#38271618)
We use Artifactory as a PyPI mirror and a private package index and it works really great.
Re:Rust Without Crates.io by amelius on Tuesday November 14, 2023 @08:34AM (#38263096)
> There's no technical solution to that, really.

There is. Theoretically speaking, you could confine libraries to their own sandbox.

But Rust can't do that yet.

Re:Rust Without Crates.io by pertique on Tuesday November 14, 2023 @11:49AM (#38265820)
Do you have other info on languages that do? In my mind, if a library is compromised and incorporated in software that touches sensitive data then there's no way to meaningfully sandbox it. Sure, the library lives in the sandbox, but so does the stuff you're trying to protect. I'm not sure that's a Rust-specific problem.
Re:Rust Without Crates.io by amelius on Tuesday November 14, 2023 @01:56PM (#38267796)
The library should live in its own sandbox, separated from the rest of the system including any other libraries. All system calls have to go through a permissions system that (e.g.) denies access by default.

There is at least one language that tries to do that (someone posted it here in a comment some time ago, but I can't find it).

Re:Rust Without Crates.io by marwis on Tuesday November 14, 2023 @07:02PM (#38271590)
Java (look up Security Manager).

Unfortunately it is deprecated and scheduled for removal because too much security is annoying and not enough people care to use it.

Re:Rust Without Crates.io by richardwhiuk on Tuesday November 14, 2023 @06:18AM (#38261866)
Every serious enterprise runs a Rust proxy - and indeed Artifactory / Azure Artifacts and others support this.
Re:Rust Without Crates.io by jrpelkonen on Tuesday November 14, 2023 @09:07AM (#38263441)
Sure, Artifactory, etc. have their places. But I am objecting to your "no true scotsman"[1] type of argument. Furthermore, the most bizarre setups I have seen have been in "serious" enterprises. Hardly an endorsement.

1: https://en.wikipedia.org/wiki/No_true_Scotsman

Re:Rust Without Crates.io by devman0 on Tuesday November 14, 2023 @10:08AM (#38264159)
I have to agree with the poster you are replying to. If an entity is not doing the bare minimum to QA software supply chain, then they are not "serious". That being said, I have seen many a large enterprise that do not treat software development as a serious endeavor and it shows.
Re:Rust Without Crates.io by brightball on Tuesday November 14, 2023 @06:56AM (#38262187)
Gitlab has this built in as well.
Re:Rust Without Crates.io by basedrum on Tuesday November 14, 2023 @07:41AM (#38262598)
Has which built in?
Re:Rust Without Crates.io by brightball on Tuesday November 14, 2023 @08:36AM (#38263112)
Package registry proxy (linked in original comment)
Re:Rust Without Crates.io by basedrum on Tuesday November 14, 2023 @09:05AM (#38263406)
That isn't a proxy, it's a registry for packages you build
Re:Rust Without Crates.io by wongarsu on Tuesday November 14, 2023 @07:06AM (#38262270)
And this is easy to do with Rust as well. The article mentions both major options: store your dependencies in your repo using the built-in `cargo vendor` command, or run a mirror like panamax that just mirrors all of crates.io (or just the packages you need, but then you run into issues with updating if crates.io is ever down).

Mirroring all of crates.io takes about a terabyte of storage, not much bandwidth and is really easy to set up, but judging by the download numbers of obscure packages there are only about 20 places in the world doing that. Maybe people haven't bothered because crates.io is so stable, maybe everyone goes the vendoring route instead.

Re:Rust Without Crates.io by galangalalgol on Tuesday November 14, 2023 @07:26AM (#38262453)
Why would you ask panamax to mirror everything though? You are maintaining a manifest of all your organizations dependencies right? Why would I mirror ancient versionsbof clap and that crate that checks your aol mail? Also, nexus doesn't have a functioning cargo plugin, it is community made and stagnant. Artifactory does support it. And I'm guessing artifactory is what most people are using for a private registry too given the state of the others.
Re:Rust Without Crates.io by wongarsu on Tuesday November 14, 2023 @08:33AM (#38263066)
Mirroring everything gives me the ability to not just build existing software independently of crates.io outages or decisions, but also to not be impacted in software development by such incidents. To me development involves using packages or package versions I might not have used before.

Of course if your development is already set up in a way that prevents you from easily adding, experimenting with or updating dependencies, maybe because of how the vetting process works, that might not be an issue for you. And many places are completely fine with just being able to build

Re:Rust Without Crates.io by galangalalgol on Tuesday November 14, 2023 @09:08AM (#38263452)
Yeah, that makes sense and we should probably expand a bit. I can't imagine wanting versions that are older than anything we support or what those things bring in. Also we prune stuff that gets unmaintained or has a cve pop up. And we don't mess with copyleft, not against it, but when everything is statically linked you get into incompatible combinations quickly.
Re:Rust Without Crates.io by devman0 on Tuesday November 14, 2023 @10:04AM (#38264092)
Having worked in enterprise software, it has been my experience that the majority of in-house repos operate in a caching mode and not mirroring. The critical element is being able to build things in CI that are being PR'd/reviewed or are already merged and in both cases the relevant dependencies should already be cached. That and being able to re-build any tagged releases, again should be cached. New libraries being temporarily unavailable are generally not going to hold up critical processes, and the upstreams have been available enough for that to never be a serious issue.
Re:Rust Without Crates.io by jamesfinlayson on Wednesday November 15, 2023 @01:18AM (#38273853)
Agreed - I can't remember what was used at my last job but you submitted a package to be mirrored and then each night it pulled in any new releases.
Re:Rust Without Crates.io by andrewaylett on Tuesday November 14, 2023 @02:16PM (#38268070)
I'm quite happy -- even in commercial development -- to not be able to download new things if the package source is down. But not being able to access my existing dependencies is a blocker: I must be able to redeploy my own stuff, and to make fixes that don't involve version bumps.

It's unlikely that I'll need a new dependency at the exact moment that the source is down, but fairly likely that if the source is down then I'll want to build something. For personal projects I'll have stuff cached locally, and I don't mind so much if I need to wait for CI. For work stuff I need to be able to fetch my dependencies in CI.

Also, hammering upstream with requests for every single build is both slow and also sort of rude.

Re:Rust Without Crates.io by sgu999 on Tuesday November 14, 2023 @07:37AM (#38262557)
> `cargo vendor`

I had no idea \o/ Thanks!

Re:Rust Without Crates.io by api on Tuesday November 14, 2023 @07:08AM (#38262291)
These days some laptops have enough storage to comfortably mirror all of multiple language package repositories especially if you use a compressed volume for them.
Re:Rust Without Crates.io by hun3 on Tuesday November 14, 2023 @07:08AM (#38262293)
> There are products (Nexus Firewall) that can check dependencies for vulnerabilities

Products can only do best effort scanning for known patterns of vulnerabilites. Those are only added after someone (or something) discovers it and verifies that it's not a false alarm. In between the time gap, scanners are ineffective and anything in your infrastructure can run the malicious code and get hacked. (Google supply chain incidents on npm or pypi.)

In general, there is always a way to bypass it, since the language is turing complete and unsandboxed. Anything going beyond that is a lie, or simply impractical. Systems with latest software and antivirus get hacked all the time. Nothing can really stop them. Why?

- https://web.archive.org/web/20160424133617/http://www.pcworl...

- https://security.stackexchange.com/questions/201992/has-it-b...

- https://en.wikipedia.org/wiki/Rice%27s_theorem

> and either block them from entering the network or fail CI pipelines.

Also, relying solely on an endpoint security product for protection is dangerous since antiviruses themselves get hacked all the time. Sonatype for an example:

- https://nvd.nist.gov/vuln/search/results?form_type=Basic&res...

Re:Rust Without Crates.io by hoosieree on Tuesday November 14, 2023 @07:56AM (#38262734)
My research is about detecting semantically similar executable code inside obfuscated and stripped programs. I don't know what commercial antivirus or vulnerability scanners use internally, but it's possible to generate similarity scores between an obfuscated/stripped unknown binary and a bunch of known binaries. I suspect commercial scanners use a lot of heuristics. I know IDA Pro has a plugin for "fingerprinting" but it's based on hashes of byte sequences and can be spoofed.

My approach is basically: train a model on a large obfuscated dataset seeded with "known" examples. While you can't say with certainty what an unknown sample contains, you can determine how similar it is to a known sample, so you can spend more of your time analyzing the really weird stuff.

The hardest part in my opinion is generating the training data. You need a good source code obfuscator for your language. I've seen a lot of papers that use obfuscator-llvm[1] to obfuscate the IR during compilation. I use Tigress[2] to obfuscate the source code because it provides more diversity, but it only supports C.

[1]: https://github.com/obfuscator-llvm/obfuscator/wiki/Installat...

[2]: https://tigress.wtf/

Re:Rust Without Crates.io by hun3 on Tuesday November 14, 2023 @10:56AM (#38264870)
Great work! For unobfuscated or lightly packed ones, I guess your approach could mostly work.

One question: how do you detect when a binary is intentionally made to statically look similar to one binary, while its behavior actually mimics another?

Re:Rust Without Crates.io by hoosieree on Thursday November 16, 2023 @09:50AM (#38290203)
That's a good question. There are Tigress transformations [1,2] that seem highly relevant to this goal, but they're harder to work with because the resulting C code isn't always compilable without errors.

In my work I'm not looking for intentional spoofing, but the obfuscations I do use [3,4,5,6,7] end up building very similar control flow structures for different functions. Maybe that fits the spirit of your question... Let me know if not.

So far I'm doing purely static analysis and control flow, but the broader field of reverse engineering includes dynamic/symbolic analysis where you track values through a running/simulated program. Great results but very costly to run.

I've been focusing on making cheap/static analysis better, so I haven't explored the dynamic/symbolic side at all yet.

[1]: https://tigress.wtf/virtualize.html

[2]: https://tigress.wtf/jitter.html

[3]: https://tigress.wtf/flatten.html

[4]: https://tigress.wtf/split.html

[5]: https://tigress.wtf/merge.html

[6]: https://tigress.wtf/encodeArithmetic.html

[7]: https://tigress.wtf/inline.html

Re:Rust Without Crates.io by tgv on Tuesday November 14, 2023 @07:23AM (#38262423)
> There are products (Nexus Firewall) that can check dependencies for vulnerabilities and either block them from entering the network or fail CI pipelines.

Once they're known. I suppose nexus firewall let log4j pass.

Re:Rust Without Crates.io by ashishbijlani on Tuesday November 14, 2023 @07:42AM (#38262602)
I’ve been building Packj [1] to detect publicly UNKNOWN dummy, malicious, abandoned, typo-squatting, and other "risky" PyPI/NPM/Ruby/PHP/Maven/Rust packages. It carries out static/dynamic/metadata analysis and scans for 40+ attributes such as num funcs/files, spawning of shell, use of SSH keys, network communication, use of decode+eval, etc. to flag risky packages. Packj Github action [2] can alert if a risky dependency is pulled into your build.

1. https://github.com/ossillate-inc/packj 2. https://github.com/ossillate-inc/packj-github-action

Re:Rust Without Crates.io by vilunov on Tuesday November 14, 2023 @07:40AM (#38262588)
Debian devs also let let4j pass.
Re:Rust Without Crates.io by frakkingcylons on Tuesday November 14, 2023 @07:57PM (#38272025)
It's pretty absurd to expect distribution maintainers to be discovering 0days.
Re:Rust Without Crates.io by oblio on Tuesday November 14, 2023 @07:51AM (#38262678)
> Once they're known.

Isn't that how life works? Unknown unknowns? :-)

> I suppose nexus firewall let log4j pass.

It should be reasonable to assume that a product dedicated to something will, on average, do this job better/faster than a random developer, though. Since that's their job.

So Nexus Firewall presumably blocks these vulnerabilities faster than the average app/system developer notices them. There's value in reducing the delta between the vulnerability exploit day and an entire ecosystem being patched/fixed.

Re:Rust Without Crates.io by livealight on Tuesday November 14, 2023 @08:01AM (#38262786)
It let log4j pass for as long as it was known to be good. Within hours of the CVE opening the tool was blocking it. The purpose of dependency firewalls is to avoid two things: known badly vulnerable packages AND known malicious packages that serve no other purpose than to steal data or drop a trojan. No security is 100% bulletproof, but it's really surprising how much of the damage is done by 7 year old CVEs. Firewalls can be useful in exactly that.
Re:Rust Without Crates.io by tikkabhuna on Tuesday November 14, 2023 @10:26AM (#38264408)
Yes, but nothing can prevent you from consuming unknown vulnerabilities.

Once log4shell was discovered it was trivial to eliminate it from the organisation. We knew exactly what projects were using it and updated them accordingly. Access logs showed us that it was no longer used and we delete it.

Re:Rust Without Crates.io by KronisLV on Tuesday November 14, 2023 @07:24AM (#38262438)
> As someone who has worked in a big corporate their entire career this statement is bizarre. This has been solved for Java for over a decade.

> Builds don't access the internet directly. You host a proxy on-premise (Nexus/Artifactory/etc) and access that. If the internet location is down, you continue as normal.

Right now I'm using Sonatype Nexus (the free version) for my personal needs: https://www.sonatype.com/products/sonatype-nexus-repository

And I do mean most things: apt packages, Docker images, Helm charts, as well as packages for Go, Java, .NET, Node, Python and Ruby, maybe even more in the future. I'm very glad that it is possible to do something like that, but honestly it's hard to do and I can easily see why most wouldn't bother: even though the configuration UI is okay and you can create users with appropriate permissions, you'll still need to have plenty of storage, manage updates and backups, setup automated cleanup tasks (especially for Docker images), in addition to the whole process on the developer's side sometimes being a nuisance.

With npm you get --registry which is one of the simpler approaches, Ruby Gems needed some CLI commands along the lines of "bundle config mirror" and other stuff, Maven needs an XML file with the configuration, in addition to publishing your own packages to those also needing more configuration. Sadly, it seems like this fragmentation of approaches is unavoidable and complexity increases with the amount of languages you use.

On the bright side, I keep control over my data, as well as have really good download/upload speeds, even on a cheap VPS. Plus you learn some vaguely useful things the more you explore if you want to go further, like how I also start with Debian/Ubuntu base container images and provision whatever tools or runtimes I need for more specialized images (e.g. my own JDK, .NET, Node etc. images).

Re:Rust Without Crates.io by oblio on Tuesday November 14, 2023 @07:57AM (#38262740)
I don't know if they ever implemented it, can it offload the storage to S3? The cost is peanuts and you stop bothering about the annoying recurrent storage issues.
Re:Rust Without Crates.io by KronisLV on Tuesday November 14, 2023 @08:18PM (#38272187)
> I don't know if they ever implemented it, can it offload the storage to S3?

There are actually multiple different kinds of blob store backends: https://help.sonatype.com/repomanager3/nexus-repository-admi... though so far I've only used the File one, because my servers have incremental backups that can be restored in a few clicks (that I've sometimes done in the past).

Re:Rust Without Crates.io by tikkabhuna on Tuesday November 14, 2023 @10:31AM (#38264483)
The UI does leave a lot to be desired, definitely! I wish they'd add specific UIs for the different formats.

I agree with the pain that some languages/package managers add as well. Its a shame package managers aren't necessarily designed to easily support writing your own mirror or switching repository.

Fair play for running your own Nexus for personal use!

Re:Rust Without Crates.io by keep_reading on Tuesday November 14, 2023 @12:21PM (#38266314)
I have CI pipelines fail when Github goes down because of crates.io being inaccessible.

Does anyone have a proxy for Rust? I'd love to run it. Please. Someone... help

edit: just learned Panamax exists for this... will try it