From aebe8392bff07e06facc487d315a8f9de4bb7c6e Mon Sep 17 00:00:00 2001 From: N04h Date: Wed, 24 Jul 2024 19:55:23 +0200 Subject: [PATCH 01/12] sed: 1: "/PORT.*STATE.*SERVICE/, ...": bad flag in substitute command: '}' --- nmapAutomator.sh | 71 ++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/nmapAutomator.sh b/nmapAutomator.sh index 9c55af3..02a26a4 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -245,46 +245,51 @@ cmpPorts() { # Print nmap progress bar # $1 is $scanType, $2 is $percent, $3 is $elapsed, $4 is $remaining progressBar() { - [ -z "${2##*[!0-9]*}" ] && return 1 - [ "$(stty size | cut -d ' ' -f 2)" -le 120 ] && width=50 || width=100 - fill="$(printf "%-$((width == 100 ? $2 : ($2 / 2)))s" "#" | tr ' ' '#')" - empty="$(printf "%-$((width - (width == 100 ? $2 : ($2 / 2))))s" " ")" - printf "In progress: $1 Scan ($3 elapsed - $4 remaining) \n" - printf "[${fill}>${empty}] $2%% done \n" - printf "\e[2A" + [ -z "${2##*[!0-9]*}" ] && return 1 + [ "$(stty size | cut -d ' ' -f 2)" -le 120 ] && width=50 || width=100 + fill="$(printf "%-${width}s" "#" | tr ' ' '#')" + fill="${fill:0:$((width * $2 / 100))}" + empty="$(printf "%-${width}s" " ")" + empty="${empty:0:$((width - ${#fill}))}" + printf "In progress: $1 Scan ($3 elapsed - $4 remaining) \n" + printf "[${fill}>${empty}] $2%% done \n" + printf "\e[2A" } + # Calculate current progress bar status based on nmap stats (with --stats-every) # $1 is nmap command to be run, $2 is progress bar $refreshRate nmapProgressBar() { - refreshRate="${2:-1}" - outputFile="$(echo $1 | sed -e 's/.*-oN \(.*\).nmap.*/\1/').nmap" - tmpOutputFile="${outputFile}.tmp" - - # Run the nmap command - if [ ! -e "${outputFile}" ]; then - $1 --stats-every "${refreshRate}s" >"${tmpOutputFile}" 2>&1 & - fi + refreshRate="${2:-1}" + outputFile="$(echo $1 | sed -e 's/.*-oN \(.*\).nmap.*/\1/').nmap" + tmpOutputFile="${outputFile}.tmp" + + # Run the nmap command + if [ ! -e "${outputFile}" ]; then + $1 --stats-every "${refreshRate}s" >"${tmpOutputFile}" 2>&1 & + fi + + # Keep checking nmap stats and calling progressBar() every $refreshRate + while { [ ! -e "${outputFile}" ] || ! grep -q "Nmap done at" "${outputFile}"; } && { [ ! -e "${tmpOutputFile}" ] || ! grep -i -q "quitting" "${tmpOutputFile}"; }; do + scanType="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -n -e '/elapsed/s/.*undergoing \(.*\) Scan.*/\1/p')" + percent="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -n -e '/% done/s/.*About \(.*\)\..*% done.*/\1/p')" + elapsed="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -n -e '/elapsed/s/Stats: \(.*\) elapsed.*/\1/p')" + remaining="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -n -e '/remaining/s/.* (\(.*\) remaining.*/\1/p')" + progressBar "${scanType:-No}" "${percent:-0}" "${elapsed:-0:00:00}" "${remaining:-0:00:00}" + sleep "${refreshRate}" + done + printf "\033[0K\r\n\033[0K\r\n" + + # Print final output, remove extra nmap noise + if [ -e "${outputFile}" ]; then + sed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/H;${x;s/^\n\|\n[^\n]*\n# Nmap.*//gp}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' + else + cat "${tmpOutputFile}" + fi + rm -f "${tmpOutputFile}" +} - # Keep checking nmap stats and calling progressBar() every $refreshRate - while { [ ! -e "${outputFile}" ] || ! grep -q "Nmap done at" "${outputFile}"; } && { [ ! -e "${tmpOutputFile}" ] || ! grep -i -q "quitting" "${tmpOutputFile}"; }; do - scanType="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -ne '/elapsed/{s/.*undergoing \(.*\) Scan.*/\1/p}')" - percent="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -ne '/% done/{s/.*About \(.*\)\..*% done.*/\1/p}')" - elapsed="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -ne '/elapsed/{s/Stats: \(.*\) elapsed.*/\1/p}')" - remaining="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -ne '/remaining/{s/.* (\(.*\) remaining.*/\1/p}')" - progressBar "${scanType:-No}" "${percent:-0}" "${elapsed:-0:00:00}" "${remaining:-0:00:00}" - sleep "${refreshRate}" - done - printf "\033[0K\r\n\033[0K\r\n" - # Print final output, remove extra nmap noise - if [ -e "${outputFile}" ]; then - sed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/H;${x;s/^\n\|\n[^\n]*\n# Nmap.*//gp}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' - else - cat "${tmpOutputFile}" - fi - rm -f "${tmpOutputFile}" -} # Nmap scan for live hosts networkScan() { From 46c748b7443e8b95cadd91a7436803132b4cac2d Mon Sep 17 00:00:00 2001 From: N04h Date: Wed, 24 Jul 2024 19:58:43 +0200 Subject: [PATCH 02/12] sed2 --- nmapAutomator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmapAutomator.sh b/nmapAutomator.sh index 02a26a4..a7a7ce1 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -282,7 +282,7 @@ nmapProgressBar() { # Print final output, remove extra nmap noise if [ -e "${outputFile}" ]; then - sed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/H;${x;s/^\n\|\n[^\n]*\n# Nmap.*//gp}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' + sed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/{H; $!d; x; s/^\n//; s/\n# Nmap.*//; p}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' else cat "${tmpOutputFile}" fi From 05e5b4e505f572d5d9daa516d5c6bfe14382455c Mon Sep 17 00:00:00 2001 From: N04h Date: Wed, 24 Jul 2024 20:12:58 +0200 Subject: [PATCH 03/12] update sed --- nmapAutomator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmapAutomator.sh b/nmapAutomator.sh index a7a7ce1..100597b 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -282,7 +282,7 @@ nmapProgressBar() { # Print final output, remove extra nmap noise if [ -e "${outputFile}" ]; then - sed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/{H; $!d; x; s/^\n//; s/\n# Nmap.*//; p}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' + sed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/{p;}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' else cat "${tmpOutputFile}" fi From c8df4fc2f8f4466f68f3f847b470e0d602eace07 Mon Sep 17 00:00:00 2001 From: N04h Date: Thu, 25 Jul 2024 20:23:36 +0200 Subject: [PATCH 04/12] update sed and for macos --- .DS_Store | Bin 0 -> 6148 bytes nmapAutomator.sh | 54 +++++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..075329f563cd0e3e9a0651028476246b6b85ac72 GIT binary patch literal 6148 zcmeHKO-sW-5Pef4ws!FY`tqORG}Kt_MW@H*pt55T?*OOtBB6P z?Aw{0x0`)|Y!-kN>-i~=0_f8fdjmE*Ovlx?tQRu-MA13wWph7UHZ#ULq1o?OK;K=0 zAr^SVDtdn-jtxJZxs4oQj4NDXifhy;aKm2B_>BA~%)4wkiP#4?XZ08r852}d^?OvE z;+b>a;RPeCu|ne_#aFKOhKGp%5%C9n#){k$7sMUU*IPskhGwRKDPRix69sr?tMv~( zT5AfJ0;a%50sTH?bj3Vi>(PBW*tjbIF=5&n`|j7Dm}!ET2W&kuLlaLWda8sghJ>4g zcsj@PP~Up=bckD-^MsWp+)yN3JS21FkldrSrhqBXRbbDDsh(=J/dev/null | sed -n -e '/elapsed/s/.*undergoing \(.*\) Scan.*/\1/p')" - percent="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -n -e '/% done/s/.*About \(.*\)\..*% done.*/\1/p')" - elapsed="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -n -e '/elapsed/s/Stats: \(.*\) elapsed.*/\1/p')" - remaining="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | sed -n -e '/remaining/s/.* (\(.*\) remaining.*/\1/p')" + scanType="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | gsed -n -e '/elapsed/s/.*undergoing \(.*\) Scan.*/\1/p')" + percent="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | gsed -n -e '/% done/s/.*About \(.*\)\..*% done.*/\1/p')" + elapsed="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | gsed -n -e '/elapsed/s/Stats: \(.*\) elapsed.*/\1/p')" + remaining="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | gsed -n -e '/remaining/s/.* (\(.*\) remaining.*/\1/p')" progressBar "${scanType:-No}" "${percent:-0}" "${elapsed:-0:00:00}" "${remaining:-0:00:00}" sleep "${refreshRate}" done @@ -282,7 +282,7 @@ nmapProgressBar() { # Print final output, remove extra nmap noise if [ -e "${outputFile}" ]; then - sed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/{p;}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' + gsed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/{p;}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' else cat "${tmpOutputFile}" fi @@ -304,15 +304,15 @@ networkScan() { # Discover live hosts with nmap nmapProgressBar "${nmapType} -T4 --max-retries 1 --max-scan-delay 20 -n -sn -oN nmap/Network_${HOST}.nmap ${subnet}/24" printf "${YELLOW}Found the following live hosts:${NC}\n\n" - cat nmap/Network_${HOST}.nmap | grep -v '#' | grep "$(echo $subnet | sed 's/..$//')" | awk {'print $5'} + cat nmap/Network_${HOST}.nmap | grep -v '#' | grep "$(echo $subnet | gsed 's/..$//')" | awk {'print $5'} elif $pingable; then # Discover live hosts with ping echo >"nmap/Network_${HOST}.nmap" for ip in $(seq 0 254); do - (ping -c 1 -${TW} 1 "$(echo $subnet | sed 's/..$//').$ip" 2>/dev/null | grep 'stat' -A1 | xargs | grep -v ', 0.*received' | awk {'print $2'} >>"nmap/Network_${HOST}.nmap") & + (ping -c 1 -${TW} 1 "$(echo $subnet | gsed 's/..$//').$ip" 2>/dev/null | grep 'stat' -A1 | xargs | grep -v ', 0.*received' | awk {'print $2'} >>"nmap/Network_${HOST}.nmap") & done wait - sed -i '/^$/d' "nmap/Network_${HOST}.nmap" + gsed -i '/^$/d' "nmap/Network_${HOST}.nmap" sort -t . -k 3,3n -k 4,4n "nmap/Network_${HOST}.nmap" else printf "${YELLOW}No ping detected.. TCP Network Scan is not implemented yet in Remote mode.\n${NC}" @@ -356,7 +356,7 @@ scriptScan() { # Modify detected OS if Nmap detects a different OS if [ -f "nmap/Script_${HOST}.nmap" ] && grep -q "Service Info: OS:" "nmap/Script_${HOST}.nmap"; then - serviceOS="$(sed -n '/Service Info/{s/.* \([^;]*\);.*/\1/p;q}' "nmap/Script_${HOST}.nmap")" + serviceOS="$(gsed -n '/Service Info/{s/.* \([^;]*\);.*/\1/p;q}' "nmap/Script_${HOST}.nmap")" if [ "${osType}" != "${serviceOS}" ]; then osType="${serviceOS}" printf "${NC}\n" @@ -403,7 +403,7 @@ fullScan() { else echo echo - printf "${YELLOW}Making a script scan on extra ports: $(echo "${extraPorts}" | sed 's/,/, /g')\n" + printf "${YELLOW}Making a script scan on extra ports: $(echo "${extraPorts}" | gsed 's/,/, /g')\n" printf "${NC}\n" nmapProgressBar "${nmapType} -sCV -p${extraPorts} --open -oN nmap/Full_Extra_${HOST}.nmap ${HOST} ${DNSSTRING}" 2 assignPorts "${HOST}" @@ -438,9 +438,9 @@ UDPScan() { if [ -n "${udpPorts}" ]; then echo echo - printf "${YELLOW}Making a script scan on UDP ports: $(echo "${udpPorts}" | sed 's/,/, /g')\n" + printf "${YELLOW}Making a script scan on UDP ports: $(echo "${udpPorts}" | gsed 's/,/, /g')\n" printf "${NC}\n" - if [ -f /usr/share/nmap/scripts/vulners.nse ]; then + if [ -f /usr/local/share/nmap/scripts/vulners.nse ]; then sudo -v nmapProgressBar "sudo ${nmapType} -sCVU --script vulners --script-args mincvss=7.0 -p${udpPorts} --open -oN nmap/UDP_Extra_${HOST}.nmap ${HOST} ${DNSSTRING}" 2 else @@ -478,7 +478,7 @@ vulnsScan() { fi # Ensure the vulners script is available, then run it with nmap - if [ ! -f /usr/share/nmap/scripts/vulners.nse ]; then + if [ ! -f /usr/local/share/nmap/scripts/vulners.nse ]; then printf "${RED}Please install 'vulners.nse' nmap script:\n" printf "${RED}https://github.com/vulnersCom/nmap-vulners\n" printf "${RED}\n" @@ -529,9 +529,9 @@ recon() { printf "${YELLOW}sudo apt install ${missingTools} -y\n" printf "${NC}\n\n" - availableRecon="$(echo "${allRecon}" | tr " " "\n" | awk -vORS=', ' '!/'"$(echo "${missingTools}" | tr " " "|")"'/' | sed 's/..$//')" + availableRecon="$(echo "${allRecon}" | tr " " "\n" | awk -vORS=', ' '!/'"$(echo "${missingTools}" | tr " " "|")"'/' | gsed 's/..$//')" else - availableRecon="$(echo "${allRecon}" | tr "\n" " " | sed 's/\ /,\ /g' | sed 's/..$//')" + availableRecon="$(echo "${allRecon}" | tr "\n" " " | gsed 's/\ /,\ /g' | gsed 's/..$//')" fi secs=30 @@ -599,7 +599,7 @@ reconRecommend() { printf "${NC}\n" printf "${YELLOW}SMTP Recon:\n" printf "${NC}\n" - echo "smtp-user-enum -U /usr/share/wordlists/metasploit/unix_users.txt -t \"${HOST}\" | tee \"recon/smtp_user_enum_${HOST}.txt\"" + echo "smtp-user-enum -U /users/share/wordlists/metasploit/unix_users.txt -t \"${HOST}\" | tee \"recon/smtp_user_enum_${HOST}.txt\"" echo fi @@ -634,11 +634,11 @@ reconRecommend() { echo "nikto -host \"${urlType}${HOST}:${port}\" | tee \"recon/nikto_${HOST}_${port}.txt\"" fi if type ffuf >/dev/null 2>&1; then - extensions="$(echo 'index' >./index && ffuf -s -w ./index:FUZZ -mc '200,302' -e '.asp,.aspx,.html,.jsp,.php' -u "${urlType}${HOST}:${port}/FUZZ" 2>/dev/null | awk -vORS=, -F 'index' '{print $2}' | sed 's/.$//' && rm ./index)" - echo "ffuf -ic -w /usr/share/wordlists/dirb/common.txt -e '${extensions}' -u \"${urlType}${HOST}:${port}/FUZZ\" | tee \"recon/ffuf_${HOST}_${port}.txt\"" + extensions="$(echo 'index' >./index && ffuf -s -w ./index:FUZZ -mc '200,302' -e '.asp,.aspx,.html,.jsp,.php' -u "${urlType}${HOST}:${port}/FUZZ" 2>/dev/null | awk -vORS=, -F 'index' '{print $2}' | gsed 's/.$//' && rm ./index)" + echo "ffuf -ic -w /users/share/wordlists/dirb/common.txt -e '${extensions}' -u \"${urlType}${HOST}:${port}/FUZZ\" | tee \"recon/ffuf_${HOST}_${port}.txt\"" else - extensions="$(echo 'index' >./index && gobuster dir -w ./index -t 30 -qnkx '.asp,.aspx,.html,.jsp,.php' -s '200,302' -u "${urlType}${HOST}:${port}" 2>/dev/null | awk -vORS=, -F 'index' '{print $2}' | sed 's/.$//' && rm ./index)" - echo "gobuster dir -w /usr/share/wordlists/dirb/common.txt -t 30 -ekx '${extensions}' -u \"${urlType}${HOST}:${port}\" -o \"recon/gobuster_${HOST}_${port}.txt\"" + extensions="$(echo 'index' >./index && gobuster dir -w ./index -t 30 -qnkx '.asp,.aspx,.html,.jsp,.php' -s '200,302' -u "${urlType}${HOST}:${port}" 2>/dev/null | awk -vORS=, -F 'index' '{print $2}' | gsed 's/.$//' && rm ./index)" + echo "gobuster dir -w /users/share/wordlists/dirb/common.txt -t 30 -ekx '${extensions}' -u \"${urlType}${HOST}:${port}\" -o \"recon/gobuster_${HOST}_${port}.txt\"" fi echo fi @@ -648,7 +648,7 @@ reconRecommend() { cms="$(grep http-generator "nmap/Script_${HOST}.nmap" | cut -d " " -f 2)" if [ -n "${cms}" ]; then for line in ${cms}; do - port="$(sed -n 'H;x;s/\/.*'"${line}"'.*//p' "nmap/Script_${HOST}.nmap")" + port="$(gsed -n 'H;x;s/\/.*'"${line}"'.*//p' "nmap/Script_${HOST}.nmap")" # case returns 0 by default (no match), so ! case returns 1 if ! case "${cms}" in Joomla | WordPress | Drupal) false ;; esac then From ebeafdc59d16b00abc1a370653852d0040c628ca Mon Sep 17 00:00:00 2001 From: Haoling Liu Date: Tue, 30 Jul 2024 20:28:39 +0200 Subject: [PATCH 05/12] both path for arm and amd --- nmapAutomator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmapAutomator.sh b/nmapAutomator.sh index eaa71ef..90a4978 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -478,7 +478,7 @@ vulnsScan() { fi # Ensure the vulners script is available, then run it with nmap - if [ ! -f /usr/local/share/nmap/scripts/vulners.nse ]; then + if [ ! -f /usr/local/share/nmap/scripts/vulners.nse ]&& [ ! -f "/usr/local/share/nmap/scripts/vulners.nse" ]; then printf "${RED}Please install 'vulners.nse' nmap script:\n" printf "${RED}https://github.com/vulnersCom/nmap-vulners\n" printf "${RED}\n" From 7ba19fe8524a98d2049d29576988f5e9a4dcc2d1 Mon Sep 17 00:00:00 2001 From: System Administrator Date: Tue, 30 Jul 2024 21:03:52 +0200 Subject: [PATCH 06/12] update to || or --- nmapAutomator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmapAutomator.sh b/nmapAutomator.sh index 90a4978..3fe38f0 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -478,7 +478,7 @@ vulnsScan() { fi # Ensure the vulners script is available, then run it with nmap - if [ ! -f /usr/local/share/nmap/scripts/vulners.nse ]&& [ ! -f "/usr/local/share/nmap/scripts/vulners.nse" ]; then + if [ ! -f /usr/local/share/nmap/scripts/vulners.nse ]|| [ ! -f "/usr/local/share/nmap/scripts/vulners.nse" ]; then printf "${RED}Please install 'vulners.nse' nmap script:\n" printf "${RED}https://github.com/vulnersCom/nmap-vulners\n" printf "${RED}\n" From e5bfc8ce5d7e1cc325eb51164b6553b01eace8ce Mon Sep 17 00:00:00 2001 From: Haoling Liu Date: Tue, 30 Jul 2024 21:19:03 +0200 Subject: [PATCH 07/12] 1 --- nmapAutomator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmapAutomator.sh b/nmapAutomator.sh index 3fe38f0..cf0b894 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -478,7 +478,7 @@ vulnsScan() { fi # Ensure the vulners script is available, then run it with nmap - if [ ! -f /usr/local/share/nmap/scripts/vulners.nse ]|| [ ! -f "/usr/local/share/nmap/scripts/vulners.nse" ]; then + if [ ! -f /opt/homebrew/share/nmap/scripts/vulners.nse ]|| [ ! -f /usr/local/share/nmap/scripts/vulners.nse ]; then printf "${RED}Please install 'vulners.nse' nmap script:\n" printf "${RED}https://github.com/vulnersCom/nmap-vulners\n" printf "${RED}\n" From a8e006fde8301de6dea1160f782b8d4b0c46564e Mon Sep 17 00:00:00 2001 From: Haoling Liu Date: Tue, 30 Jul 2024 21:29:49 +0200 Subject: [PATCH 08/12] 2 --- nmapAutomator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmapAutomator.sh b/nmapAutomator.sh index cf0b894..e027d72 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -478,7 +478,7 @@ vulnsScan() { fi # Ensure the vulners script is available, then run it with nmap - if [ ! -f /opt/homebrew/share/nmap/scripts/vulners.nse ]|| [ ! -f /usr/local/share/nmap/scripts/vulners.nse ]; then + if [ ! -f "/opt/homebrew/share/nmap/scripts/vulners.nse" ]|| [ ! -f "/usr/local/share/nmap/scripts/vulners.nse" ]; then printf "${RED}Please install 'vulners.nse' nmap script:\n" printf "${RED}https://github.com/vulnersCom/nmap-vulners\n" printf "${RED}\n" From 885aba2d29b831975975b8aec0ad29d80bbc2582 Mon Sep 17 00:00:00 2001 From: Haoling Liu Date: Tue, 30 Jul 2024 21:52:07 +0200 Subject: [PATCH 09/12] 3 --- nmapAutomator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmapAutomator.sh b/nmapAutomator.sh index e027d72..65ee3c4 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -478,7 +478,7 @@ vulnsScan() { fi # Ensure the vulners script is available, then run it with nmap - if [ ! -f "/opt/homebrew/share/nmap/scripts/vulners.nse" ]|| [ ! -f "/usr/local/share/nmap/scripts/vulners.nse" ]; then + if [ ! -f /opt/homebrew/share/nmap/scripts/vulners.nse ] && [ ! -f /usr/local/share/nmap/scripts/vulners.nse ]; then printf "${RED}Please install 'vulners.nse' nmap script:\n" printf "${RED}https://github.com/vulnersCom/nmap-vulners\n" printf "${RED}\n" From 34de8ca3bfd87b0d1434ca57789b3c8af4aee8da Mon Sep 17 00:00:00 2001 From: su2700 Date: Tue, 28 Jul 2026 23:05:49 +0200 Subject: [PATCH 10/12] chore: configure LF line endings for shell scripts in .gitattributes --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfdb8b7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf From aeeddd425253706335333dfa42dd6cb2dae4b10e Mon Sep 17 00:00:00 2001 From: su2700 Date: Tue, 28 Jul 2026 23:20:55 +0200 Subject: [PATCH 11/12] refactor: improve cross-platform compatibility by implementing dynamic sed detection and shell cleanup mechanisms. --- nmapAutomator.sh | 64 +++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/nmapAutomator.sh b/nmapAutomator.sh index 65ee3c4..b915d1d 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash #by @21y4d # Define ANSI color variables @@ -8,6 +8,24 @@ GREEN='\033[0;32m' NC='\033[0m' origIFS="${IFS}" +# Detect OS and set appropriate sed syntax (supporting macOS & Linux) +kernel="$(uname -s)" +if command -v gsed >/dev/null 2>&1; then + SED="gsed" + SED_INLINE="g${SED_INLINE}" +elif [ "${kernel}" = "Darwin" ]; then + SED="sed" + SED_INLINE="${SED_INLINE} ''" +else + SED="sed" + SED_INLINE="${SED_INLINE}" +fi + +cleanup() { + rm -f ./.index_$$ *.tmp 2>/dev/null +} +trap cleanup EXIT INT TERM + # Start timer elapsedStart="$(date '+%H:%M:%S' | awk -F: '{print $1 * 3600 + $2 * 60 + $3}')" REMOTE=false @@ -185,21 +203,21 @@ header() { assignPorts() { # Set $commonPorts based on Port scan if [ -f "nmap/Port_$1.nmap" ]; then - commonPorts="$(awk -vORS=, -F/ '/^[0-9]/{print $1}' "nmap/Port_$1.nmap" | gsed 's/.$//')" + commonPorts="$(awk -vORS=, -F/ '/^[0-9]/{print $1}' "nmap/Port_$1.nmap" | ${SED} 's/.$//')" fi # Set $allPorts based on Full scan or both Port and Full scans if [ -f "nmap/Full_$1.nmap" ]; then if [ -f "nmap/Port_$1.nmap" ]; then - allPorts="$(awk -vORS=, -F/ '/^[0-9]/{print $1}' "nmap/Port_$1.nmap" "nmap/Full_$1.nmap" | gsed 's/.$//')" + allPorts="$(awk -vORS=, -F/ '/^[0-9]/{print $1}' "nmap/Port_$1.nmap" "nmap/Full_$1.nmap" | ${SED} 's/.$//')" else - allPorts="$(awk -vORS=, -F/ '/^[0-9]/{print $1}' "nmap/Full_$1.nmap" | gsed 's/.$//')" + allPorts="$(awk -vORS=, -F/ '/^[0-9]/{print $1}' "nmap/Full_$1.nmap" | ${SED} 's/.$//')" fi fi # Set $udpPorts based on UDP scan if [ -f "nmap/UDP_$1.nmap" ]; then - udpPorts="$(awk -vORS=, -F/ '/^[0-9]/{print $1}' "nmap/UDP_$1.nmap" | gsed 's/.$//')" + udpPorts="$(awk -vORS=, -F/ '/^[0-9]/{print $1}' "nmap/UDP_$1.nmap" | ${SED} 's/.$//')" if [ "${udpPorts}" = "Al" ]; then udpPorts="" fi @@ -239,7 +257,7 @@ checkOS() { # Add any extra ports found in Full scan # No args needed cmpPorts() { - extraPorts="$(echo ",${allPorts}," | gsed 's/,\('"$(echo "${commonPorts}" | gsed 's/,/,\\|/g')"',\)\+/,/g; s/^,\|,$//g')" + extraPorts="$(echo ",${allPorts}," | ${SED} 's/,\('"$(echo "${commonPorts}" | ${SED} 's/,/,\\|/g')"',\)\+/,/g; s/^,\|,$//g')" } # Print nmap progress bar @@ -261,7 +279,7 @@ progressBar() { # $1 is nmap command to be run, $2 is progress bar $refreshRate nmapProgressBar() { refreshRate="${2:-1}" - outputFile="$(echo $1 | gsed -e 's/.*-oN \(.*\).nmap.*/\1/').nmap" + outputFile="$(echo $1 | ${SED} -e 's/.*-oN \(.*\).nmap.*/\1/').nmap" tmpOutputFile="${outputFile}.tmp" # Run the nmap command @@ -271,10 +289,10 @@ nmapProgressBar() { # Keep checking nmap stats and calling progressBar() every $refreshRate while { [ ! -e "${outputFile}" ] || ! grep -q "Nmap done at" "${outputFile}"; } && { [ ! -e "${tmpOutputFile}" ] || ! grep -i -q "quitting" "${tmpOutputFile}"; }; do - scanType="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | gsed -n -e '/elapsed/s/.*undergoing \(.*\) Scan.*/\1/p')" - percent="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | gsed -n -e '/% done/s/.*About \(.*\)\..*% done.*/\1/p')" - elapsed="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | gsed -n -e '/elapsed/s/Stats: \(.*\) elapsed.*/\1/p')" - remaining="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | gsed -n -e '/remaining/s/.* (\(.*\) remaining.*/\1/p')" + scanType="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | ${SED} -n -e '/elapsed/s/.*undergoing \(.*\) Scan.*/\1/p')" + percent="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | ${SED} -n -e '/% done/s/.*About \(.*\)\..*% done.*/\1/p')" + elapsed="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | ${SED} -n -e '/elapsed/s/Stats: \(.*\) elapsed.*/\1/p')" + remaining="$(tail -n 2 "${tmpOutputFile}" 2>/dev/null | ${SED} -n -e '/remaining/s/.* (\(.*\) remaining.*/\1/p')" progressBar "${scanType:-No}" "${percent:-0}" "${elapsed:-0:00:00}" "${remaining:-0:00:00}" sleep "${refreshRate}" done @@ -282,7 +300,7 @@ nmapProgressBar() { # Print final output, remove extra nmap noise if [ -e "${outputFile}" ]; then - gsed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/{p;}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' + sed -n '/PORT.*STATE.*SERVICE/,/^# Nmap/{p;}' "${outputFile}" | awk '!/^SF(:|-).*$/' | grep -v 'service unrecognized despite' else cat "${tmpOutputFile}" fi @@ -304,15 +322,15 @@ networkScan() { # Discover live hosts with nmap nmapProgressBar "${nmapType} -T4 --max-retries 1 --max-scan-delay 20 -n -sn -oN nmap/Network_${HOST}.nmap ${subnet}/24" printf "${YELLOW}Found the following live hosts:${NC}\n\n" - cat nmap/Network_${HOST}.nmap | grep -v '#' | grep "$(echo $subnet | gsed 's/..$//')" | awk {'print $5'} + cat nmap/Network_${HOST}.nmap | grep -v '#' | grep "$(echo $subnet | ${SED} 's/..$//')" | awk {'print $5'} elif $pingable; then # Discover live hosts with ping echo >"nmap/Network_${HOST}.nmap" for ip in $(seq 0 254); do - (ping -c 1 -${TW} 1 "$(echo $subnet | gsed 's/..$//').$ip" 2>/dev/null | grep 'stat' -A1 | xargs | grep -v ', 0.*received' | awk {'print $2'} >>"nmap/Network_${HOST}.nmap") & + (ping -c 1 -${TW} 1 "$(echo $subnet | ${SED} 's/..$//').$ip" 2>/dev/null | grep 'stat' -A1 | xargs | grep -v ', 0.*received' | awk {'print $2'} >>"nmap/Network_${HOST}.nmap") & done wait - gsed -i '/^$/d' "nmap/Network_${HOST}.nmap" + ${SED_INLINE} '/^$/d' "nmap/Network_${HOST}.nmap" sort -t . -k 3,3n -k 4,4n "nmap/Network_${HOST}.nmap" else printf "${YELLOW}No ping detected.. TCP Network Scan is not implemented yet in Remote mode.\n${NC}" @@ -356,7 +374,7 @@ scriptScan() { # Modify detected OS if Nmap detects a different OS if [ -f "nmap/Script_${HOST}.nmap" ] && grep -q "Service Info: OS:" "nmap/Script_${HOST}.nmap"; then - serviceOS="$(gsed -n '/Service Info/{s/.* \([^;]*\);.*/\1/p;q}' "nmap/Script_${HOST}.nmap")" + serviceOS="$(${SED} -n '/Service Info/{s/.* \([^;]*\);.*/\1/p;q}' "nmap/Script_${HOST}.nmap")" if [ "${osType}" != "${serviceOS}" ]; then osType="${serviceOS}" printf "${NC}\n" @@ -403,7 +421,7 @@ fullScan() { else echo echo - printf "${YELLOW}Making a script scan on extra ports: $(echo "${extraPorts}" | gsed 's/,/, /g')\n" + printf "${YELLOW}Making a script scan on extra ports: $(echo "${extraPorts}" | ${SED} 's/,/, /g')\n" printf "${NC}\n" nmapProgressBar "${nmapType} -sCV -p${extraPorts} --open -oN nmap/Full_Extra_${HOST}.nmap ${HOST} ${DNSSTRING}" 2 assignPorts "${HOST}" @@ -438,7 +456,7 @@ UDPScan() { if [ -n "${udpPorts}" ]; then echo echo - printf "${YELLOW}Making a script scan on UDP ports: $(echo "${udpPorts}" | gsed 's/,/, /g')\n" + printf "${YELLOW}Making a script scan on UDP ports: $(echo "${udpPorts}" | ${SED} 's/,/, /g')\n" printf "${NC}\n" if [ -f /usr/local/share/nmap/scripts/vulners.nse ]; then sudo -v @@ -529,9 +547,9 @@ recon() { printf "${YELLOW}sudo apt install ${missingTools} -y\n" printf "${NC}\n\n" - availableRecon="$(echo "${allRecon}" | tr " " "\n" | awk -vORS=', ' '!/'"$(echo "${missingTools}" | tr " " "|")"'/' | gsed 's/..$//')" + availableRecon="$(echo "${allRecon}" | tr " " "\n" | awk -vORS=', ' '!/'"$(echo "${missingTools}" | tr " " "|")"'/' | ${SED} 's/..$//')" else - availableRecon="$(echo "${allRecon}" | tr "\n" " " | gsed 's/\ /,\ /g' | gsed 's/..$//')" + availableRecon="$(echo "${allRecon}" | tr "\n" " " | ${SED} 's/\ /,\ /g' | ${SED} 's/..$//')" fi secs=30 @@ -634,10 +652,10 @@ reconRecommend() { echo "nikto -host \"${urlType}${HOST}:${port}\" | tee \"recon/nikto_${HOST}_${port}.txt\"" fi if type ffuf >/dev/null 2>&1; then - extensions="$(echo 'index' >./index && ffuf -s -w ./index:FUZZ -mc '200,302' -e '.asp,.aspx,.html,.jsp,.php' -u "${urlType}${HOST}:${port}/FUZZ" 2>/dev/null | awk -vORS=, -F 'index' '{print $2}' | gsed 's/.$//' && rm ./index)" + extensions="$(echo 'index' >./.index_$$ && ffuf -s -w ./.index_$$:FUZZ -mc '200,302' -e '.asp,.aspx,.html,.jsp,.php' -u "${urlType}${HOST}:${port}/FUZZ" 2>/dev/null | awk -vORS=, -F 'index' '{print $2}' | ${SED} 's/.$//' && rm ./.index_$$)" echo "ffuf -ic -w /users/share/wordlists/dirb/common.txt -e '${extensions}' -u \"${urlType}${HOST}:${port}/FUZZ\" | tee \"recon/ffuf_${HOST}_${port}.txt\"" else - extensions="$(echo 'index' >./index && gobuster dir -w ./index -t 30 -qnkx '.asp,.aspx,.html,.jsp,.php' -s '200,302' -u "${urlType}${HOST}:${port}" 2>/dev/null | awk -vORS=, -F 'index' '{print $2}' | gsed 's/.$//' && rm ./index)" + extensions="$(echo 'index' >./.index_$$ && gobuster dir -w ./.index_$$ -t 30 -qnkx '.asp,.aspx,.html,.jsp,.php' -s '200,302' -u "${urlType}${HOST}:${port}" 2>/dev/null | awk -vORS=, -F 'index' '{print $2}' | ${SED} 's/.$//' && rm ./.index_$$)" echo "gobuster dir -w /users/share/wordlists/dirb/common.txt -t 30 -ekx '${extensions}' -u \"${urlType}${HOST}:${port}\" -o \"recon/gobuster_${HOST}_${port}.txt\"" fi echo @@ -648,7 +666,7 @@ reconRecommend() { cms="$(grep http-generator "nmap/Script_${HOST}.nmap" | cut -d " " -f 2)" if [ -n "${cms}" ]; then for line in ${cms}; do - port="$(gsed -n 'H;x;s/\/.*'"${line}"'.*//p' "nmap/Script_${HOST}.nmap")" + port="$(${SED} -n 'H;x;s/\/.*'"${line}"'.*//p' "nmap/Script_${HOST}.nmap")" # case returns 0 by default (no match), so ! case returns 1 if ! case "${cms}" in Joomla | WordPress | Drupal) false ;; esac then From ef5de7edcd0db37411ce7040f265c1e1c0d3a553 Mon Sep 17 00:00:00 2001 From: su2700 Date: Tue, 28 Jul 2026 23:31:10 +0200 Subject: [PATCH 12/12] test --- README.md | 88 ++++++++++++++++++++++++++++++++++++------------ nmapAutomator.sh | 59 ++++++++++++++++++++++++++++++-- 2 files changed, 123 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 837e9e6..af60ace 100644 --- a/README.md +++ b/README.md @@ -52,42 +52,77 @@ The entire script output is also saved, which you can view with `less -r outputD ----- -## Requirements: -[ffuf](https://github.com/ffuf/ffuf), which we can install with: +## Requirements & Dependency Installation + +`nmapAutomator` automatically detects missing tools and notifies you. Below are setup commands for **Kali Linux** and **macOS**. + +### 1. Kali Linux / Debian / Ubuntu + +Most recon tools come pre-installed in [Kali Linux](https://www.kali.org) and [Parrot OS](https://www.parrotsec.org). To install or update all required and optional recon tools: + ```bash -sudo apt update -sudo apt install ffuf -y +sudo apt update && sudo apt install -y \ + nmap ffuf gobuster nikto sslscan joomscan \ + wpscan smbmap enum4linux dnsrecon snmp ldap-utils ``` -Or [Gobuster](https://github.com/OJ/gobuster) '*v3.0 or higher*', which we can install with: +### 2. macOS (Homebrew) + +`nmapAutomator` fully supports macOS (with both native BSD `sed` or Homebrew `gnu-sed`). Install dependencies using [Homebrew](https://brew.sh): + ```bash -sudo apt update -sudo apt install gobuster -y +brew update && brew install \ + nmap ffuf gobuster nikto sslscan wpscan gnu-sed ``` -Other recon tools used within the script include: +### Other Recon Tools Supported: |[nmap Vulners](https://github.com/vulnersCom/nmap-vulners)|[sslscan](https://github.com/rbsec/sslscan)|[nikto](https://github.com/sullo/nikto)|[joomscan](https://github.com/rezasp/joomscan)|[wpscan](https://github.com/wpscanteam/wpscan)| |:-:|:-:|:-:|:-:|:-:| |[droopescan](https://github.com/droope/droopescan)|[smbmap](https://github.com/ShawnDEvans/smbmap)|[enum4linux](https://github.com/portcullislabs/enum4linux)|[dnsrecon](https://github.com/darkoperator/dnsrecon)|[odat](https://github.com/quentinhardy/odat)| |[smtp-user-enum](https://github.com/pentestmonkey/smtp-user-enum)|snmp-check|snmpwalk|ldapsearch|| - -Most of these should be installed by default in [Parrot OS](https://www.parrotsec.org) and [Kali Linux](https://www.kali.org). -*If any recon recommended tools are found to be missing, they will be automatically omitted, and the user will be notified.* - -## Installation: +*If any recommended recon tools are missing, they will be automatically omitted during scans and reported via `na -c`.* + +----- + +## Installation & Global Alias Setup + +### 1. Clone the Repository ```bash git clone https://github.com/21y4d/nmapAutomator.git -sudo ln -s $(pwd)/nmapAutomator/nmapAutomator.sh /usr/local/bin/ +cd nmapAutomator +``` + +### 2. Make it Globally Executable +Create a symbolic link in `/usr/local/bin`: +```bash +sudo ln -s $(pwd)/nmapAutomator.sh /usr/local/bin/nmapAutomator +``` + +### 3. Add `na` Short Alias +To run `nmapAutomator` using the short `na` command: + +**Option A: Create a direct symlink (`na`)** *(Recommended)* +```bash +sudo ln -s $(pwd)/nmapAutomator.sh /usr/local/bin/na +``` + +**Option B: Add a shell alias (`~/.bashrc` or `~/.zshrc`)** +```bash +# For Bash (Linux / macOS) +echo "alias na='nmapAutomator.sh'" >> ~/.bashrc && source ~/.bashrc + +# For Zsh (macOS / Kali default) +echo "alias na='nmapAutomator.sh'" >> ~/.zshrc && source ~/.zshrc ``` ----- ## Usage: ``` -./nmapAutomator.sh -h +na -h Usage: nmapAutomator.sh -H/--host -t/--type -Optional: [-r/--remote ] [-d/--dns ] [-o/--output ] [-s/--static-nmap ] +Optional: [-r/--remote ] [-d/--dns ] [-o/--output ] [-s/--static-nmap ] [-c/--check-deps] Scan Types: Network : Shows all live hosts in the host's network (~15 seconds) @@ -100,12 +135,23 @@ Scan Types: All : Runs all the scans (~20-30 minutes) ``` -**Example scans**: +**Check installed dependencies**: +```bash +na -c +# or +na --check-deps ``` -./nmapAutomator.sh --host 10.1.1.1 --type All -./nmapAutomator.sh -H 10.1.1.1 -t Basic -./nmapAutomator.sh -H academy.htb -t Recon -d 1.1.1.1 -./nmapAutomator.sh -H 10.10.10.10 -t network -s ./nmap + +**Example scans**: +```bash +# Shorthand: Automatically runs All scans on target IP +na 10.1.1.1 + +# Explicit scans: +na --host 10.1.1.1 --type All +na -H 10.1.1.1 -t Port +na -H academy.htb -t Recon -d 1.1.1.1 +na -H 10.10.10.10 -t Network -s ./nmap ``` ------ diff --git a/nmapAutomator.sh b/nmapAutomator.sh index b915d1d..3dc17cc 100755 --- a/nmapAutomator.sh +++ b/nmapAutomator.sh @@ -30,11 +30,55 @@ trap cleanup EXIT INT TERM elapsedStart="$(date '+%H:%M:%S' | awk -F: '{print $1 * 3600 + $2 * 60 + $3}')" REMOTE=false +checkDeps() { + echo + printf "${GREEN}------------------ Checking Dependencies ------------------${NC}\n\n" + coreTools="nmap sed awk grep ping host" + reconTools="ffuf gobuster nikto sslscan joomscan wpscan smbmap enum4linux dnsrecon droopescan odat smtp-user-enum snmp-check snmpwalk ldapsearch" + + missingList="" + printf "${YELLOW}%-20s %-15s${NC}\n" "Tool Name" "Status" + printf "${YELLOW}%-20s %-15s${NC}\n" "---------" "------" + + printf "${YELLOW}[Core Dependencies]${NC}\n" + for tool in ${coreTools}; do + if command -v "${tool}" >/dev/null 2>&1; then + printf " %-18s ${GREEN}[INSTALLED]${NC}\n" "${tool}" + else + printf " %-18s ${RED}[MISSING]${NC}\n" "${tool}" + missingList="${missingList} ${tool}" + fi + done + + printf "\n${YELLOW}[Recon Dependencies]${NC}\n" + for tool in ${reconTools}; do + if command -v "${tool}" >/dev/null 2>&1; then + printf " %-18s ${GREEN}[INSTALLED]${NC}\n" "${tool}" + else + printf " %-18s ${RED}[MISSING]${NC}\n" "${tool}" + missingList="${missingList} ${tool}" + fi + done + + echo + if [ -n "${missingList}" ]; then + printf "${RED}Missing tools:${NC}${missingList}\n\n" + printf "${YELLOW}You can install missing packages with:${NC}\n" + printf " sudo apt update && sudo apt install -y${missingList}\n\n" + else + printf "${GREEN}All core and recon dependencies are installed!${NC}\n\n" + fi +} + # Parse flags while [ $# -gt 0 ]; do key="$1" case "${key}" in + -c | --check-deps) + CHECK_DEPS=true + shift + ;; -H | --host) HOST="$2" shift @@ -72,13 +116,22 @@ while [ $# -gt 0 ]; do done set -- ${POSITIONAL} -# Legacy flags support, if run without -H/-t +# If -c/--check-deps flag passed, check dependencies and exit +if [ "${CHECK_DEPS}" = "true" ]; then + checkDeps + exit 0 +fi + +# Legacy flags & shorthand positional argument support (e.g. 'na 192.168.1.1' defaults to 'All') if [ -z "${HOST}" ]; then HOST="$1" + if [ -n "$2" ]; then + TYPE="$2" + fi fi -if [ -z "${TYPE}" ]; then - TYPE="$2" +if [ -n "${HOST}" ] && [ -z "${TYPE}" ]; then + TYPE="All" fi # Legacy types support, if quick/basic used