Web頁面執行shell命令

2022-03-01 06:04:33 字數 1221 閱讀 4177

本文以apache為web伺服器為例

安裝apache服務

啟動apache

建立shell指令碼

cd /var/www/cgi-bin/

vim shell

#!/bin/sh

alias urldecode='

sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b"

'echo -e "

content-type: text/plain\n

"decoded_str=`echo $query_string |urldecode`

echo -e "

`$decoded_str` \n

"

shell

測試:在瀏覽器中輸入即可列出目錄

提供web介面

cd /var/www/html

vim index.html

head>

command:

id='

in'>

'f()

'>send

id='

out'>

index.html

注意修改**中ip,更改為伺服器ip或網域名稱

效果圖如圖所示

cgi-bin目錄執行shell指令碼格式

#!/bin/sh

printf "content-type: text/plain\n\n"

your_commands_here

安全性優化

限制使用者訪問cgi-bin目錄,修改/etc/httpd/conf/httpd.conf

allowoverride none

options none

require all granted

deny from all

allow from 127.0.0.1 your-ip-address

配置http頁面賬號密碼訪問,也可實現安全性

弊端無法執行複雜的指令碼命令,如帶有" |等特殊符號的命令無法執行,如yum、top命令執行結果不完整、僅適用於簡單帶輸出指令碼命令,指令碼執行賬號為apache

Web頁面執行shell命令

本文以apache為web伺服器為例yum y install httpd sudo systemctl restart httpd cd var www cgi bin vim shell bin sh alias urldecode sed s g s x g xargs 0 printf b ...

Android執行shell命令

android執行shell命令 一 方法 執行乙個shell命令,並返回字串值 param cmd 命令名稱 引數組成的陣列 例如 param workdirectory 命令執行路徑 例如 system bin return 執行結果組成的字串 throws ioexception public...

python執行shell命令

在此比較一下兩種方法執行系統命令的方法,以方便於日後運用 1.os.system system command exit status execute the command a string in a subshell.僅僅在乙個子終端執行系統命令,而不能獲取命令執行後的返回資訊.os.syste...