News for hackers. Stuff that matters.
Re:Rm -rf remains by kator on Saturday June 14, 2014 @10:56AM (#7892869)
Related but fun commands to try along same vane (as root).

(WARNING: These make a mess don't do this on a system you care about)

(NOTE: Spaces matter here watch if you cut-paste)

    yes > /dev/mem
    dd if=/dev/urandom of=$(mount|sed -n '/\/ /s/ .*//p')
    rm -fr /lib /usr/lib
    rm /etc/passwd && init 6
In the good 'ole days me and a friend of mine would boot a Xenix system from an 8" floppy that was designed to bring up console and tty1 with a bash prompt. The goal was to see who could crash the system the fastest.. Then we'd copy the disk, reboot and do it again.. The number one rule was you couldn't use the same one-liner in the next round so each round got more and more convoluted.
Re:Rm -rf remains by ISL on Saturday June 14, 2014 @03:56PM (#7893527)
I did the third one (mv, not rm) to a system I cared about with a full hard disk early in my linux tutelage.

Educational day.

Re:Rm -rf remains by JoshTriplett on Saturday June 14, 2014 @03:08AM (#7892258)
This is a nice exploration of what's built into the bash shell. Handy not just for when you rm -rf / , but also for when you suddenly find yourself lacking in usable tools. For instance, I've had an upgrade break the dynamic linker (/lib/ld-linux.so.2 or /lib64/ld-linux-x86-64.so.2), and suddenly no dynamically linked program runs.

However, the solution given here assumes you have a bash compiled with support for /dev/tcp. You can, instead, paste the necessary executables directly over the existing connection to the system, encoded to survive that transport.

Re:Rm -rf remains by userbinator on Saturday June 14, 2014 @06:06AM (#7892477)
This is basically a bootstrapping problem and turns out to rest on these critical functions:

- being able to create a file containing arbitrary data

- being able to make a file executable

- being able to execute a file

Would the same be possible if your shell was not bash but one with fewer features, like e.g. POSIX sh? That doesn't even require echo to be a builtin (it only has the 3rd function above), so it might be a dead end, but maybe there's some other way...

Re:Rm -rf remains by jacobgreenleaf on Saturday June 14, 2014 @10:22PM (#7894180)
Alternatively, I think it might be possible if you can cause arbitrary interrupts to the operating system and control some registers and perhaps the stack as well. Depending on the shell, you might be able to do this; you certainly don't need the standard command-line tools for chmod and cat, because those are just small programs that pass through to actual system calls:

http://docs.cs.up.ac.za/programming/asm/derick_tut/syscalls....

Re:Rm -rf remains by haberman on Sunday June 15, 2014 @12:29AM (#7894380)
How are you going to cause arbitrary interrupts from the shell?
Re:Rm -rf remains by obiterdictum on Saturday June 14, 2014 @05:02AM (#7892404)
The classic version of it:

http://lug.wsu.edu/node/414

Re:Rm -rf remains by lsh123 on Saturday June 14, 2014 @10:24AM (#7892814)
I've had very similar experience. I believe it was Oracle 7 and one smart guy tried to install it into the root folder. The only problem was that the install script did 'rm -rf $DESTFOLDER' at the beginning. Luckily for us, the script actually printed the commands on the console and the guy quickly realized what is about to happen. He aborted the install script but by the time /etc and quite a few other things were gone.

It was a Sun OS 5.1 I believe on a pretty big box (for its time) with A LOT of user data. We recovered it using roughly the same steps. We didn't need to write in assembler though since we've had Sun compiler tool chain in /opt that survived. At the end, we used a modem to connect the damaged box to another one with a tape backup. It took about 12 hours to copy the data over.

Re:Rm -rf remains by jevinskie on Sunday June 15, 2014 @12:19AM (#7894355)
On Macs, /Applications is probably the first to go. I stopped an rm -rf /* (intended .*) inside /Applications/Adium.app. I'm really glad I wasn't using a SSD!! Adium itself started acting very odd. One of the many issues was that sending a message to a specific person actually sent the message to a group chat. I was lucky to figure that one out before I cursed out the group chat while describing my stupidity.
Re:Rm -rf remains by dunk010 on Sunday June 15, 2014 @04:29PM (#7896209)
Thanks for that. I had this strong feeling that this was very much basically the same as something (classic) that I had read before.
Re:Rm -rf remains by philips on Saturday June 14, 2014 @03:33PM (#7893469)
Mildly interesting: CoreOS is shooting for `rm -rf /` being safe and similar to a "factory reset" on your phone. Here are the results on vagrant after rebooting a machine where `rm -rf /` was done: http://i.imgur.com/VMuPkf3.png
Re:Rm -rf remains by galapago on Saturday June 14, 2014 @03:20AM (#7892272)
This article feels like a "Minecraft" in desolated Linux system.
Re:Rm -rf remains by andrey-p on Saturday June 14, 2014 @05:43AM (#7892453)
I was thinking more of a post-apocalyptic sci-fi story.

> We lost everything in the Big War. Luckily our last supplies of Bash built-ins were left intact. If we pool our resources and use our remaining executable bits wisely, we might just last through the nuclear winter.

Re:Rm -rf remains by hobo_mark on Saturday June 14, 2014 @11:30AM (#7892943)
That was more or less the premise behind 0x10c http://en.wikipedia.org/wiki/0x10c
Re:Rm -rf remains by logicchains on Saturday June 14, 2014 @04:30AM (#7892368)
If somebody actually made something like that it'd make debugging even funner than it already is.
Re:Rm -rf remains by cgriswald on Saturday June 14, 2014 @12:49PM (#7893108)
Reminds me of the Doom process manager: http://psdoom.sourceforge.net/
Re:Rm -rf remains by adrianhoward on Saturday June 14, 2014 @03:32AM (#7892292)
About 25 years ago I saw somebody do a "chmod a-rwx ." as root, at root on an SunOs box. Recovering from that was almost entertaining ;-)
Re:Rm -rf remains by onthedole on Saturday June 14, 2014 @07:50PM (#7893995)
A few years ago I changed over from a Dell PC Keyboard to an Apple keyboard.

I had to delete some files in a temp folder and typed the command as I was always used to, and pressed enter.

Immediately realised something was wrong and then saw the "*" replaced with a "/". Did not have a fun afternoon.

http://i.imgur.com/4k4SOpF.jpg

Re:Rm -rf remains by pbhjpbhj on Saturday June 14, 2014 @01:02PM (#7893139)
My worst has been accidentally removing zip - back in my Slackware days IIRC. I was trying to upgrade and so I removed the old one and then went to install the new one and couldn't install it again as the packager used zip and all the downloads I could find were tar.gz (or tar.bz2 or whatever).

That was the first, and last time I think, that I used cpio. Phew.

Re:Rm -rf remains by fjarlq on Saturday June 14, 2014 @03:49AM (#7892308)
But the superuser privileges should have overridden such directory permissions, even 25 years ago....
Re:Rm -rf remains by DmitriRavinoff on Saturday June 14, 2014 @04:18AM (#7892347)
Yes, but if you can't run the chmod binary...
Re:Rm -rf remains by fjarlq on Saturday June 14, 2014 @04:24AM (#7892357)
No, root can still run chmod, because its superuser privileges override the new restrictive directory perms. That was my point.

Maybe the original problem was actually "chmod a-rwx /bin/chmod" ... That would mean even the superuser couldn't execute /bin/chmod anymore, so you'd have to do something more creative to reset the executable bit on /bin/chmod. Like compile a C program that calls the chmod system call, or:

  mv /bin/chmod /bin/chmod.orig
  cp -p /bin/ls /bin/chmod
  cp /bin/chmod.orig /bin/chmod
Re:Rm -rf remains by pantalaimon on Saturday June 14, 2014 @07:52AM (#7892613)
> Like compile a C program that calls the chmod system call

The compiler wouldn't be executable anymore either

Re:Rm -rf remains by claviola on Saturday June 14, 2014 @11:05AM (#7892886)
Yes, it would. Like he said, you can still run it unless you specifically removed its permissions.
Re:Rm -rf remains by mtdewcmu on Saturday June 14, 2014 @04:24AM (#7892359)
The explanation for what made him type that is what interests me. It would be like accidentally cutting your left hand clean off with a steak knife while you were eating dinner.
Re:Rm -rf remains by johnchristopher on Saturday June 14, 2014 @07:25AM (#7892576)
My bash is set to use vim bindings (set -o vi) and I constantly loop through commands. I am guilty of doing this while sleepy and sometimes I think I have cd to another directory when in fact I have not. I rm-ed (too) many things that way.
Re:Rm -rf remains by mtdewcmu on Saturday June 14, 2014 @12:15PM (#7893041)
I gave the vi mode a very short try, but it doesn't seem to make as much sense in a shell. If it has you accidentally deleting things, you might want to ask how much is it really worth. In vim you can undo.
Re:Rm -rf remains by r4um on Sunday June 15, 2014 @07:15AM (#7894995)
One can use the shared library loader to invoke binaries that do not have executable bit set, comes in handy once in a while.

  $ cp /bin/chmod .
  $ chmod -x ./chmod
  $ /lib/ld-2.19.so ./chmod
  ./chmod: missing operand
  Try './chmod --help' for more information.
Re:Rm -rf remains by pbhjpbhj on Saturday June 14, 2014 @01:54PM (#7893222)
My worst has been accidentally removing zip - back in my Slackware days IIRC. I was trying to upgrade and so I removed the old one and then went to install the new one and couldn't install it again as the packager used zip and all the downloads I could find were tar.gz (or tar.bz2 or whatever).

That was the first, and last time I think, that I used cpio.

Re:Rm -rf remains by ibisum on Saturday June 14, 2014 @08:23AM (#7892655)
Oh, the pain! I remember doing that 25 years ago too, ouch.
Re:Rm -rf remains by haberman on Saturday June 14, 2014 @04:07AM (#7892331)
That was a really fun read. I had no idea that bash supported loading plugins out of shared libraries with the "enable" command.
Re:Rm -rf remains by voltagex_ on Saturday June 14, 2014 @05:56AM (#7892472)
I'm trying to work out how enable is useful over dropping an executable in /bin or ~/bin (not in this story, but in general)

It's definitely a nice trick, though.

Edit: http://cfajohnson.com/shell/articles/dynamically-loadable/

Re:Rm -rf remains by jl6 on Saturday June 14, 2014 @07:05AM (#7892532)
bash enable sounds like a potential attack vector for executing code on a filesystem that would otherwise not allow it.
Re:Rm -rf remains by s-macke on Saturday June 14, 2014 @12:30PM (#7893071)
Thanks for the nice description!

For my small Linux emulator I put the link in the Wiki after "Destroy the system" :)

https://github.com/s-macke/jor1k/wiki/Explore-the-emulator#r...

The system runs already on Busybox, so the whole binary is in RAM. Is there a way to restore the binary from /proc ? Or to restore the symlinks and maybe link them to /proc/self/exe or so?

Re:Rm -rf remains by general_failure on Saturday June 14, 2014 @10:04AM (#7892776)
Re:Rm -rf remains by barosl on Saturday June 14, 2014 @03:48AM (#7892307)
I lol'd on an attempt to find the executables to overwrite. It does make sense, though the applicable files are already gone.
Re:Rm -rf remains by kuschku on Saturday June 14, 2014 @04:12AM (#7892337)
Shouldn't you still be able to directly invoke ld-linux.so to load the ELF binary, even if it's marked as non-executable?
Re:Rm -rf remains by 0x0 on Saturday June 14, 2014 @05:09AM (#7892416)
That won't help when it has been deleted :)
Re:Rm -rf remains by rburhum on Saturday June 14, 2014 @11:28AM (#7892934)
There may be an obvious reason, but if using another machine is fair game as he did in one of the examples, then why did OP not just copy ls/chmod/etc from another machine to poke around?
Re:Rm -rf remains by jsnell on Saturday June 14, 2014 @11:49AM (#7892981)
How are you proposing he copy it from another machine? There's no file transfer program, client or server, remaining. Nor is there a way to mount an external filesystem. The whole point of the exercise is to bootstrap up from the few remaining resources to the point where you can "just" copy stuff in from another machine.
Re:Rm -rf remains by rburhum on Saturday June 14, 2014 @11:01PM (#7894231)
If the ssh connection remains (it is what he is using to poke around afterall), you can tunnel through the active connection without having to create a new one http://unix.stackexchange.com/questions/2857/ssh-easily-copy...
Re:Rm -rf remains by thrownaway2424 on Saturday June 14, 2014 @06:15PM (#7893852)
Yeah, which is why probably the first thing I would have copied over would not have been busybox, but probably rz.
Re:Rm -rf remains by yoha on Saturday June 14, 2014 @04:03AM (#7892323)
Already posted → https://hn.algolia.com/?q=lambdaosp

It would have make more sense to at least change the title to make it more explicit.

Re:Rm -rf remains by dang on Saturday June 14, 2014 @04:57AM (#7892396)
Reposts are fine when an item hasn't had significant attention within about the last year. The previous post had 10 points, but 0 comments, so this repost probably doesn't count as a dupe.
Re:Rm -rf remains by lolo_ on Saturday June 14, 2014 @04:42AM (#7892383)