-
Notifications
You must be signed in to change notification settings - Fork 0
/
zpentest.plugin.zsh
124 lines (110 loc) · 4.14 KB
/
zpentest.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
########## Plugin: zpentest ##########
# ----------------------------------------#
########## Author: Doc0x1 ##########
########## Version: 1.11 ##########
# ----------------------------------------#
########## github.com/Doc0x1 ##########
# ----------------------------------------#
#$ To make pentests easier, this plugin will set persistent environment variables for LHOST and RHOST
penteston() {
# Determine the location of .zshrc
ZSHRC_LOCATION="${ZDOTDIR:-$HOME}/.zshrc"
# Check if .zshrc exists
if [ ! -f "$ZSHRC_LOCATION" ]; then
printf "Error: .zshrc not found at $ZSHRC_LOCATION. Please create it first.\n"
return 1
fi
# Initialize variables
local NEW_LHOST=''
local NEW_RHOST=''
# Regex pattern for validating IP address
local ip_regex='^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
# Process arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--lhost)
NEW_LHOST=$2
shift 2
;;
--rhost)
NEW_RHOST=$2
shift 2
;;
*)
printf "This function will set persistent environment variables for LHOST and RHOST.\n"
printf "Usage: penteston [--lhost <local_ip>] [--rhost <remote_ip>]\n"
return 1
;;
esac
done
# Default LHOST to tun0 IP if not provided
if [[ -z "$NEW_LHOST" ]]; then
if ip addr show tun0 &> /dev/null; then
NEW_LHOST=$(ip -4 addr show tun0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
else
printf "Error: tun0 interface not found and no LHOST provided.\n"
return 1
fi
fi
# Update LHOST if valid
if [[ -n "$NEW_LHOST" ]]; then
if [[ "$NEW_LHOST" =~ $ip_regex ]]; then
export LHOST=$NEW_LHOST
if grep -q 'export LHOST=' "$ZSHRC_LOCATION"; then
sed -i "s/export LHOST=.*/export LHOST=$LHOST/" "$ZSHRC_LOCATION"
else
echo "export LHOST=$LHOST" >>"$ZSHRC_LOCATION"
fi
printf "Setting LHOST variable to $LHOST\n"
else
printf "Error: Invalid LHOST IP address format.\n"
return 1
fi
elif [[ -z "$LHOST" ]]; then
printf "Error: LHOST not provided and not currently set. Please specify --lhost.\n"
return 1
fi
# Update RHOST if provided and valid
if [[ -n "$NEW_RHOST" ]]; then
if [[ "$NEW_RHOST" =~ $ip_regex ]]; then
export RHOST=$NEW_RHOST
if grep -q 'export RHOST=' "$ZSHRC_LOCATION"; then
sed -i "s/export RHOST=.*/export RHOST=$RHOST/" "$ZSHRC_LOCATION"
else
echo "export RHOST=$RHOST" >>"$ZSHRC_LOCATION"
fi
printf "Setting RHOST variable to $RHOST\n"
else
printf "Error: Invalid RHOST IP address format.\n"
return 1
fi
elif [[ -z "$RHOST" ]]; then
printf "Error: RHOST not provided and not currently set. Please specify --rhost.\n"
return 1
fi
# If neither LHOST nor RHOST are provided, exit with an error
if [[ -z "$NEW_LHOST" && -z "$NEW_RHOST" ]]; then
printf "Error: Neither LHOST nor RHOST provided. Please specify at least one.\n"
return 1
fi
printf "Pentest variables updated.\n"
printf "Pentesting Environment now online.\n"
}
#$ Use this function when done with the pentest.
pentestoff() {
# Determine the location of .zshrc
ZSHRC_LOCATION="${ZDOTDIR:-$HOME}/.zshrc"
# Check if .zshrc exists
if [ ! -f "$ZSHRC_LOCATION" ]; then
printf "Error: .zshrc not found at $ZSHRC_LOCATION.\n"
return 1
fi
printf "This function will unset the LHOST and RHOST variables and remove them from $ZSHRC_LOCATION.\n"
printf "Use it when you are finished pentesting.\n"
# Unset variables and remove from .zshrc
unset LHOST RHOST
sed -i '/export LHOST=/d' "$ZSHRC_LOCATION"
sed -i '/export RHOST=/d' "$ZSHRC_LOCATION"
printf "Unset LHOST and RHOST variables and removed them from $ZSHRC_LOCATION\n"
printf "Pentesting Environment now offline.\n"
}