"permission denied error"但脚本运行良好



我正在观看Heath Adams臭名昭著的初学者网络渗透性测试视频,并试图制作nmap staging脚本。

谁能解释一下为什么我得到这个讨厌的权限被拒绝错误,我定义了端口变量,即使我的脚本一直运行顺利,直到这一点?

这是我正在尝试的舞台脚本:

#!/bin/bash
#creating a temp directory to store the output of initial scan
mkdir tempStager
#scannig with given flags and storing the results
echo beginning nmap scan
nmap $*  > tempStager/scan.txt
echo basic nmap scan complete
#retrieving open ports
cat tempStager/scan.txt |grep tcp |cut -d " " -f 1| tr -d "/tcp" > tempStager/ports.txt
sleep 2
ports=cat tempStager/ports.txt| awk '{printf "%s,",$0}' tempStager/ports.txt
ip=echo $* | awk 'NF{ print $NF }'
#scanning with -A
#echo ""
#echo starting nmap scan with -A
#nmap -A -p$ports $ip

#removing temp directory
#rm -r tempStager```
ports=cat tempStager/ports.txt| awk '{printf "%s,",$0}' tempStager/ports.txt

将变量赋值为"cat",然后尝试将tempStager/ports.txt作为可执行文件执行。但是这个文件不是一个可执行文件(它没有设置x位,所以它不能被执行。

ports只存在于(可能的)程序的运行时,它在程序终止后不可用(程序立即终止,因为您的shell无法运行它)。

您还指定了stdin要awk的文件。

如果您想将awk的输出分配给一个变量,您必须使用命令替换:

ports="$(awk '{printf "%s,",$0}' tempStager/ports.txt)"

最新更新