People often ask me "How did you learn how to hack?" The answer: by reading. This page is a collection of the blog posts and other articles that I have accumulated over the years of my journey. Enjoy!
node-tar promises that any extraction will NOT overwrite files outside the given directory. Since NPM install deals with tarballs, finding a bypass would be super interesting!tarball extraction validates that an absolute path is not being used. But, this check looks weak, as only a single substring comparison; this comparison simply tried to strip off the beginning path if it had a '/'. Putting /// (three slashes) would change to // (two slashes), bypassing the filter. Now, we can write a file to any location upon installation!isAbsolute function to check to see if the path was absolute or not. If we could find a way to get a difference between the resolve (executor) and isAbsolute (parser) we could bypass this check. C:/ can mark an absolute path. Using C:/different/root, the path.resolve function has a weird special case when the second parameter is an absolute path; it just resolves it! Additionally, the double dot (../) is only done between path deliminators. As a result, C:../ is a valid drive that we can use. This allowed for a minimal directory traversal (one directory up). Using a symlinked package, this could be used to do more damage though. node-tar handles hardlinks and symbolic links (but not NPM). But, there is a guarantee that these will not overwrite files out of the current directory. However, there is a directory cache which executes these checks. If we could get a fake entry in the cache, we could use it to do the classic symlink and hardlink attack, resulting in arbitrary files being written to the system! \\ should be checked on Windows but NOT Unix. Now, the same bug could bypass the filtering functionality because the FS was Unix and not Windows. The same exploit as before works except that the file name a\\x can be used instead in the cache.