开发者

Inject parameter in hardcoded tar command

I'm using a linux software solution that uses the tar command to backup huge amounts of data. The command which is hardcoded into the binary which calls the tar is:

/bin/tar --exclude "/backup" --exclude / --ignore-failed-read -cvjf - /pbackup 2>>'/tar_err.log' |  split -b 1000m - '/backup/temp/backup.tar.bz2'

There is no chance to change the command, as it is harcoded. It uses bzip2 to compress the data. I experienced a strong performance improvement (up to 60%) when using the parameter --use-compress-prog=pbzip2 which utilizes all CPU cores. By symlinking the bzip2 from /bin/bzip2 to the pbzip2 binary I tried to trick the software, however when monitoring the process it still uses bzip2 as I tink this is built into tar.

I know it is a tricky q开发者_如何学Gouestion but is there any way to utilize pbzip2 without changing this command that is externally called?

My system is Debian Sequeeze.

Thanks very much!


Danger: ugly solution ahead; backup the binary before proceeding

First of all, check if the hardcoded string is easily accessible: use strings on your binary, and see if it displays the string you said (probably it will be in several pieces, e.g. /bin/tar, --exclude, --ignore-failed-read, ...).

If this succeeds, grab your hex editor of choice, open the binary and look for the hardcoded string; if it's split in several pieces, the one you need is the one containing /bin/tar; overwrite tar with some arbitrary three-letter name, e.g. fkt (fake tar; a quick Google search didn't turn up any result for /usr/bin/fkt, so we should be safe).

The program should now call your /usr/bin/fkt instead of the regular tar.

Now, put in your /bin a script like this:

#!/bin/sh
/bin/tar --use-compress-prog=pbzip2 $*

call it with the name you chose before (fkt) and set the permissions correctly (they should be 755 and owned by root). This script just takes all the parameters it gets and call the real tar, adding in front of them the parameter you need.


Another solution, that I suggested in the comments, may be creating a chroot just for the application, renaming tar to some other name (realtar, maybe?) and calling the script above tar (obviously now you should change the /bin/tar inside the script to /bin/realtar).

If the program is not updated very often and the trick worked at the first try I would probably go with the first solution, setting up and maintaining chroots is not fun.


Why not move /bin/tar to (say) /bin/tar-original

Then create a script /bin/tar to do whatever you want it to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜