2013-02-16 79 views
4

是否有執行二進制「流」的bash命令?有一個很好的方法可以直接從Internet上加載和運行shell腳本。直接從curl執行二進制文件

爲例:

curl http://j.mp/spf13-vim3 -L -o - | sh 

是否有可能不保存文件,CHMOD等運行二進制文件?

類似:

curl http://example.com/compiled_file | exec_binary 
+0

你試過了嗎?curl http://j.mp/spf13-vim3 -L -o - | | xargs sh'?對於二進制文件,你可以編寫一個腳本,保存一個臨時文件,通過chmod添加執行權並運行它。但是所有這些行爲都會帶來巨大的安全風險。 – harpun 2013-02-16 11:40:59

+0

是的,這是一個安全風險,但我知道這個文件,這不是問題。一個shell腳本是可能的,但我正在尋找一個沒有shell腳本的更好的解決方案。 – NaN 2013-02-16 11:44:05

回答

8

Unix的內核,我知道希望二進制可執行文件被存儲在磁盤上。這是必需的,因此他們可以執行任意偏移量的查找操作,並將文件內容映射到內存中。因此,從標準輸入直接執行二進制流是不可能的。

您可以做的最好的方法是編寫一個腳本,通過將數據保存到臨時文件中來間接完成您想要的操作。

#!/bin/sh 

# Arrange for the temporary file to be deleted when the script terminates 
trap 'rm -f "/tmp/exec.$$"' 0 
trap 'exit $?' 1 2 3 15 

# Create temporary file from the standard input 
cat >/tmp/exec.$$ 

# Make the temporary file executable 
chmod +x /tmp/exec.$$ 

# Execute the temporary file 
/tmp/exec.$$