-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zsh.functions
318 lines (267 loc) · 8.88 KB
/
.zsh.functions
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
alph_sort(){
for f in *; do
if [ -f "$f" ]; then
mkdir -p "${f:0:1}"
mv "$f" "${f:0:1}"
fi
done
}
az_all_spns(){
az ad sp list --output=table --query='[].{Name:displayName,Enabled:accountEnabled,\
uyURL:homepage,Publisher:publisherName,MetadataURL:samlMetadataUrl}'
}
az_all_users(){
az ad user list --output=table --query='[].{Created:createdDateTime,UPN:userPrincipalName,Name:displayName,\
Title:jobTitle,Department:department,Email:mail,UserId:mailNickname,Phone:telephoneNumber,\
Mobile:mobile,Enabled:accountEnabled}'
}
az_dump_apps(){
az ad app list --output=table --query='[].{Name:displayName,URL:homepage}'
}
az_dump_group_members(){
az ad group member list --output=json \
--query='[].{Created:createdDateTime,UPN:userPrincipalName,Name:displayName,\
Title:jobTitle,Department:department,Email:mail,UserId:mailNickname,Phone:telephoneNumber,\
Mobile:mobile,Enabled:accountEnabled}' --group='$1'
}
az_dump_groups(){
az ad group list --output=json --query='[].{Group:displayName,Description:description}'
}
az_examine_app(){
az ad app list --output=json --identifier-uri='$1'
}
az_one_spn(){
az ad sp list --output=table --display-name='$1'
}
az_user_upn(){
az ad user list --output=json \
--query='[].{Created:createdDateTime,UPN:userPrincipalName,Name:displayName,\
Title:jobTitle,Department:department,Email:mail,UserId:mailNickname,Phone:telephoneNumber,\
Mobile:mobile,Enabled:accountEnabled}' --upn='$1'
}
bcbc(){
## Fix for brew doctor warnings if using pyenv
if which pyenv >/dev/null 2>&1; then
brew='env PATH=${PATH//$(pyenv root)\/shims:/} brew'
fi
## Fix potential tap issues
brew tap --repair
## Brew Diagnotic
echo "${yellow}==>${reset} Running Brew Diagnotic..."
brew doctor
brew missing 2>&1
echo -e "${green}==>${reset} Brew Diagnotic Finished."
## Link all unlinked kegs
# brew list -1 | while read line; do brew unlink $line; brew link $line; done
}
cd() { builtin cd "$@"; ls; }
cdf() {
target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
if [ "$target" != "" ]; then
cd "$target"; pwd
else
echo 'No Finder window found' >&2
fi
}
cidr2ip() {
cdrr=$(nmap -sL -n "$1" 2>/dev/null | grepip | sort -Vu)
echo $cdrr
cdrc=$(echo $cdrr | wc -l)
echo '\n' $cdrc 'IPs'
}
cisa() {
cisa_csv=$(curl -s https://www.cisa.gov/sites/default/files/csv/known_exploited_vulnerabilities.csv)
cisa_cve=$(echo $cisa_csv | tail -n +2 | cut -d ',' -f 1 | sort -Vu | sed -e 's/^/"/;s/$/",/' | tr '\n' ' ' | sed 's/.\{2\}$//')
echo "CVE Count: "
echo -n $cisa_csv | wc -l
echo -n $cisa_cve | pbcopy
echo "\nCVE list in clipboard"
}
clipboard(){
if command -v xclip 1>/dev/null; then
if [[ -p /dev/stdin ]] ; then
xclip -i -selection clipboard
else
xclip -o -selection clipboard
fi
else
echo "Remember to install xclip"
fi
}
csrf(){
curl -s -c $1 "$2" | awk -F 'value' '/user_token/ {print $2}' | cut -d "'" -f 2
}
frmt(){
awk '{ if ($1 ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) printf(" '\''%s'\'',\n", $1); else printf(" '\''%s'\'',\n", $1); }'
}
gistx(){
cd /opt/gists
rm -rf .git
git init
git remote add origin `clipboard`
git pull origin master
echo '\nDONEZO\n'
ls
}
# Function to match email addresses using ripgrep, then filter to only show the emails with grep, case-insensitive and error-suppressed
grepeml() {
rg -Nao --no-ignore -i "\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}\b" "$@" 2>/dev/null |
command grep -Eoi "\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}\b"
}
# Function to match IPv4 addresses using ripgrep, then filter to only show the IPs with grep
grepip() {
rg -Nao --no-ignore -e '\b((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.)){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\b' "$@" |
command grep -Eo '\b((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.)){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\b'
}
# Function to match both IPv4 and IPv6 addresses using ripgrep, then filter to only show the IPs with grep
grepip46() {
rg -Nao --no-ignore -e '\b((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.)){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\b' \
-e '([0-9a-f]{1,4}:){3,7}[0-9a-f]{1,4}' "$@" |
command grep -Eo '\b((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.)){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\b|([0-9a-f]{1,4}:){3,7}[0-9a-f]{1,4}'
}
# Function to match IPv6 addresses using ripgrep, then filter to only show the IPv6 addresses with grep, case-insensitive and error-suppressed
grepipv6() {
rg -Nao --no-ignore -i '([0-9a-fA-F]{1,4}:){3,7}[0-9a-fA-F]{1,4}' "$@" 2>/dev/null |
command grep -Eoi '([0-9a-fA-F]{1,4}:){3,7}[0-9a-fA-F]{1,4}'
}
impaste(){
# Generate a unique temporary filename
tempfile=$(mktemp -t clipboard.XXXXXXXXXX.png)
# Save the clipboard image to the temporary file
osascript -e 'set theImage to the clipboard as «class PNGf»' \
-e "set theFile to open for access POSIX file \"$tempfile\" with write permission" \
-e 'write theImage to theFile' \
-e 'close access theFile'
# Output the image data to stdout
cat "$tempfile"
# Delete the temporary file
rm "$tempfile"
}
ipy() {
local PY_BIN
local IPYTHON
local PYV
# This quick way will work if ipython is in the virtualenv
PY_BIN="$(python -c 'import sys; print(sys.executable)')"
IPYTHON="$(dirname "$PY_BIN")/ipython"
if [[ -x "$IPYTHON" ]]; then
"$IPYTHON"
else
# Ask the current python what version it is
PYV="$(python -c 'import sys; print(".".join(str(i) for i in sys.version_info[:2]))')"
echo "Looking for iPython for Python $PYV"
# In a new shell (where pyenv should load if equipped) try to find that version
PY_BIN="$($SHELL -i -c "python$PYV -c 'import sys; print(sys.executable)'")"
"$(dirname "$PY_BIN")/ipython"
fi
}
localip(){
ifconfig | grep 'inet ' | grep -v '127.0.0.1'\
| cut -d: -f2 | awk '{ print $2}' | tail -n 1
}
localips(){
ifconfig | grep 'inet ' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $2}'
}
lr2sr(){
lr1=$(pbpaste | cut -d '.' -f 1-4 | cut -d '-' -f 1)
lr2=$(pbpaste | cut -d '.' -f 7)
echo $lr1-$lr2
}
lscsv() {
ls -lT | awk '/^-/ && $1=$1' OFS=","
}
mcd() {
mkdir -p "$1" && cd "$1";
}
# mkenv(){
# cwd_tmp=`sudo echo 'env_'"${PWD##*/}"`
# sudo python -m virtualenv $cwd_tmp
# }
# mk3nv(){
# cwd_tmp=`sudo echo 'env_'"${PWD##*/}"`
# sudo python3 -m venv $cwd_tmp
# }
md5list () {
while read -r line || [ -n "$line" ]
do
echo -n $line | md5
done
}
mountshares(){
vmware-hgfsclient | while read folder; do
echo "[i] Mounting ${folder} (/mnt/hgfs/${folder})"
mkdir -p "/mnt/hgfs/${folder}"
umount -f "/mnt/hgfs/${folder}" 2>/dev/null
vmhgfs-fuse -o allow_other -o auto_unmount ".host:/${folder}" "/mnt/hgfs/${folder}"
done
sleep 2s
}
mp4togif() {
ffmpeg -i $1.mp4 -r 10 -f image2pipe -vcodec ppm - | \
convert -delay 5 -loop 0 - output.gif
}
msf(){
service postgresql start
msfdb init
tmp_ip=`localip`
sed -i '$ d' /root/.msf5/msfconsole.rc
echo -e "set lhost" $tmp_ip >> /root/.msf5/msfconsole.rc
msfconsole -r /root/.msf5/msfconsole.rc
}
pskill(){
ps -ef | rg -i $1 | rg -v 'rg' | sed 's/ \+/ /g' | cut -d ' ' -f 2 | xargs kill -9
}
reinstall_apt(){
apt-get install dselect
dpkg --set-selections < pkglist.textapt-get dselect-upgrade
}
restart-vm-tools(){
killall -q -w vmtoolsd
vmware-user-suid-wrapper vmtoolsd -n vmusr 2>/dev/null
vmtoolsd -b /var/run/vmroot 2>/dev/null
}
sessionid(){
grep PHPSESSID $1 | awk -F ' ' '{print $7}'
}
subdirexec() {
find . -maxdepth 1 -type d \( ! -name . \) \
-exec bash -c "cd '{}' && pwd && $1 && echo 'success'" \;
}
subdirgitadd() {
find . -maxdepth 1 -type d \( ! -name . \) \
-exec bash -c "cd '{}' && pwd && git add -u && echo 'success'" \;
}
unroll() {
pbpaste | tr ', ' '\n' | sort -Vu | sed '/^[[:space:]]*$/d' > ./.tmp_ip_list.txt
cdrr=$(nmap -sL -n -T5 --open -iL ./.tmp_ip_list.txt 2>/dev/null | grepip | sort -Vu)
echo $cdrr
echo $cdrr | pbcopy
cdrc=$(echo $cdrr | wc -l)
echo '\n' $cdrc 'IPs'
rm ./.tmp_ip_list.txt
}
unroll_nosort() {
pbpaste | tr ', ' '\n' | sed '/^[[:space:]]*$/d' > ./.tmp_ip_list.txt
cdrr=$(nmap -sL -n -T5 --open -iL ./.tmp_ip_list.txt 2>/dev/null | grepip)
echo $cdrr
echo $cdrr | pbcopy
cdrc=$(echo $cdrr | wc -l)
echo '\n' $cdrc 'IPs'
rm ./.tmp_ip_list.txt
}
webmap(){
docker stop webmap
docker rm webmap
docker pull rev3rse/webmap
curl -sL http://bit.ly/webmapsetup | bash
}
whodat(){ openssl s_client -showcerts -connect $1:443 | grep 'CN=' }
whocerts(){
echo "1. Running openssl check:" && echo \
| openssl s_client -showcerts -servername $1 -connect $1:443 2>/dev/null \
| openssl x509 -inform pem -noout -text \
&& echo "2. Running nslookup" \
&& nslookup -vc -type=ANY $1 \
&& echo "3. Running nmap" \
&& nmap -p 443 --script ssl-cert $1
}