-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·129 lines (100 loc) · 3.06 KB
/
init.sh
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
125
126
127
128
129
#!/bin/bash
# This script autogenerates the default pentesting and reporting template for me so that I don't have to make the folders and files myself.
# It also adds template stuff to the files so it is easy to work with.
usage="""
Automatically Setup a Penetration Testing Workspace with essenatial directories and initial recon scripts.
Usage: ./init.sh <flags>
FLAG REQURED DEFAULT COMMAND
-i IP Yes None IP address of the target machine
-n Name Yes None Name of the Target Machine (or challenge or any friendly name for reporting)
-d dir No . Base Directory for the project folder
-u Name No \$(whoami) Name/Slang/Slug of Tester or User
-s No unset Whether to run the inital scan or not (this is a boolean flag, it does not require a value)
(Assuming the installation directory is /opt/reporting, the following could be used as an example command)
Example: /opt/reporting/init.sh -i TARGET_IP -n MACHINE_NAME -s
"""
m_ip=""
m_name=""
t_dir="."
tester_name=""
scans=0
src_dir='/opt/github/reporting'
### Function to check if parameter is empty or not
function isempty() {
if [ ! -z "$1" -a "$1" != " " ]; then
return 1;
fi
return -1;
}
### Parse flags and arguments
while getopts i:n:d:u:s flag
do
case "${flag}" in
i) m_ip=${OPTARG};;
n) m_name=${OPTARG};;
d) t_dir=${OPTARG};;
u) tester_name=${OPTARG};;
s) scans=1;;
esac
done
### Null check to avoid un-necessary issues
isempty $m_ip
if [[ $? -ne 1 ]]; then
echo "[x] Invalid Machine IP"
echo $usage;
exit;
fi
isempty $m_name
if [[ $? -ne 1 ]]; then
echo "[x] Empty Machine Name"
echo $usage;
exit;
fi
isempty $t_dir
if [[ $? -ne 1 ]]; then
echo "[x] Target Directory Empty, will use the current directory"
t_dir="."
fi
isempty $tester_name
if [[ $? -ne 1 ]]; then
echo "[x] Tester Name Not specified, using current username as tester name"
tester_name="$(whoami)"
fi
echo $(ls $src_dir)
### Make workspace
echo "[-] Creating Workspace"
w_dir="$t_dir/$m_name"
mkdir -p "$w_dir/scans"
mkdir -p "$w_dir/exploits"
mkdir -p "$w_dir/scripts"
mkdir -p "$w_dir/notes"
mkdir -p "$w_dir/resources"
echo "[-] Generating README.md"
shopt -s globstar
readme_content_head="# REPORTING - $m_name"
readme_content_div="-----------"
readme_content_subhead="> $tester_name | $(date | cut -d " " -f1,2,3,4)"
remote_loc="$w_dir/README.md"
cp "$src_dir/README_PARTIAL.md" $remote_loc
printf '%s\n' 0a "$readme_content_head" "$readme_content_div" "$readme_content_subhead" . w | ed -s "$remote_loc"
echo "[-] Copying Files"
echo "$m_ip" > "$w_dir/target.txt"
cp "$src_dir/Creds.md" "$w_dir/notes/"
cp "$src_dir/Enum.md" "$w_dir/notes/"
cp "$src_dir/scans.sh" "$w_dir/scans/"
echo "[-] Files Copied to $w_dir/*"
chmod +x "$w_dir/scans/scans.sh"
cd $w_dir
echo "[-] Project Setup complete"
### Scan if asked to
if [[ $scans -eq 1 ]]; then
echo "[-] Scanning $m_ip for open ports."
if [[ "$UID" -ne 0 ]]; then
echo "[x] Elevated previliges required. Execute the following to continue the scans"
echo "[x] sudo ./scans/scans.sh $(cat target.txt)"
exit 1
fi
cd ./scans/
exec ./scans.sh $m_ip
cd ..
fi