Skip to content

Commit

Permalink
Update rapidenum.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
fulco committed May 15, 2024
1 parent e6b1867 commit c6912c1
Showing 1 changed file with 38 additions and 40 deletions.
78 changes: 38 additions & 40 deletions rapidenum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
DEFAULT_OUTPUT_DIR="./HostServices"
DEFAULT_MAX_RATE=1000
DEFAULT_TIMEOUT=600
LOG_FILE="./scan.log"

# Function to display usage information
usage() {
Expand All @@ -18,7 +19,12 @@ usage() {
# Function to log messages with timestamps
log() {
local message="$1"
echo "$(date '+%Y-%m-%d %H:%M:%S'): $message"
echo "$(date '+%Y-%m-%d %H:%M:%S'): $message" | tee -a "$LOG_FILE"
}

# Validate if the input is a positive integer
is_positive_integer() {
[[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -gt 0 ]
}

# Parse command-line arguments
Expand All @@ -31,8 +37,24 @@ while getopts ":d:s:r:t:" opt; do
case $opt in
d) output_dir="$OPTARG" ;;
s) IFS=',' read -ra services <<< "$OPTARG" ;;
r) max_rate="$OPTARG" ;;
t) timeout="$OPTARG" ;;
r)
if is_positive_integer "$OPTARG"; then
max_rate="$OPTARG"
else
log "Error: Rate must be a positive integer"
usage
exit 1
fi
;;
t)
if is_positive_integer "$OPTARG"; then
timeout="$OPTARG"
else
log "Error: Timeout must be a positive integer"
usage
exit 1
fi
;;
\?) log "Error: Invalid option -$OPTARG"; usage; exit 1 ;;
:) log "Error: Option -$OPTARG requires an argument"; usage; exit 1 ;;
esac
Expand All @@ -46,6 +68,9 @@ fi

network_range="$1"

# Trap signals for graceful exit
trap 'log "Script interrupted."; exit 1' INT TERM

# Check if Nmap is installed
if ! command -v nmap &>/dev/null; then
log "Error: Nmap is not installed. Please install Nmap and try again."
Expand All @@ -57,44 +82,17 @@ mkdir -p "$output_dir"

# Define the services and their corresponding ports
declare -A services_tcp=(
["ftp"]=21
["ssh"]=22
["telnet"]=23
["smtp"]=25
["dns"]=53
["http"]=80
["pop3"]=110
["imap"]=143
["https"]=443
["smb"]=445
["mssql"]=1433
["oracle"]=1521
["mysql"]=3306
["rdp"]=3389
["postgresql"]=5432
["vnc"]=5900
["http-alt"]=8080
["https-alt"]=8443
["smtps"]=465
["imaps"]=993
["pop3s"]=995
["mongodb"]=27017
["socks"]=1080
["squid"]=3128
["rpcbind"]=111
["pptp"]=1723
["ftp"]=21 ["ssh"]=22 ["telnet"]=23 ["smtp"]=25 ["dns"]=53
["http"]=80 ["pop3"]=110 ["imap"]=143 ["https"]=443 ["smb"]=445
["mssql"]=1433 ["oracle"]=1521 ["mysql"]=3306 ["rdp"]=3389
["postgresql"]=5432 ["vnc"]=5900 ["http-alt"]=8080 ["https-alt"]=8443
["smtps"]=465 ["imaps"]=993 ["pop3s"]=995 ["mongodb"]=27017
["socks"]=1080 ["squid"]=3128 ["rpcbind"]=111 ["pptp"]=1723
)

declare -A services_udp=(
["dns"]=53
["dhcp-server"]=67
["dhcp-client"]=68
["tftp"]=69
["snmp"]=161
["ntp"]=123
["ldap"]=389
["ws-discovery"]=3389
["nfs"]=2049
["dns"]=53 ["dhcp-server"]=67 ["dhcp-client"]=68 ["tftp"]=69
["snmp"]=161 ["ntp"]=123 ["ldap"]=389 ["ws-discovery"]=3389 ["nfs"]=2049
)

# Perform a ping sweep to identify live hosts
Expand All @@ -118,9 +116,9 @@ for service in "${services[@]:-${!services_tcp[@]} ${!services_udp[@]}}"; do
output_file="$output_dir/${service}_hosts.txt"

if [[ "$protocol" == "TCP" ]]; then
nmap -sV --min-rate "$max_rate" --max-retries 2 --host-timeout "${timeout}s" -p "$port" --open -oG - "$live_hosts" | awk '/Status: Open/{print $2}' > "$output_file"
nmap -sV --min-rate "$max_rate" --max-retries 2 --host-timeout "${timeout}s" -p "$port" --open -oG - $live_hosts | awk '/Status: Open/{print $2}' > "$output_file"
else
nmap -sU -sV --min-rate "$max_rate" --max-retries 2 --host-timeout "${timeout}s" -p "$port" --open -oG - "$live_hosts" | awk '/Status: Open/{print $2}' > "$output_file"
nmap -sU -sV --min-rate "$max_rate" --max-retries 2 --host-timeout "${timeout}s" -p "$port" --open -oG - $live_hosts | awk '/Status: Open/{print $2}' > "$output_file"
fi

log "Scan results saved to $output_file"
Expand Down

0 comments on commit c6912c1

Please sign in to comment.