Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ACCESS YOUR TERMINAL FROM YOUR

Browsers - BUTTERFLY

Butterfly - A tool for accessing your terminal locally or remotely, from your web browser.
If you have a LAN with a number of machines running GNU / Linux. You may need to access a
remote terminal to perform various tasks. For this, the tools are numerous, starting with
alternatives such as Shellinabox, FireSSH or Secure Shell.
But Butterfly is another utility written in Python, which aims to provide users with an easy way
to access a local or remote shell, from any web browser and without any third-party plugins.

You will be easily way to access to your machine, and you will be able to take advantage of some
additional options, allowing you for example to use keyboard shortcuts.

Features Of Butterfly:
 Native browser scroll and search
 Theming in css / sass (20 preset themes) endless possibilities!
 HTML in your terminal! cat images and use <table>
 Multiple sessions support (à la screen -x) to simultaneously access a terminal from
several places on the planet!
 Secure authentication with X509 certificates!
 16,777,216 colors support!
 Keyboard text selection!
 Desktop notifications on terminal output!
 Geolocation from browser!
 May work on firefox too!

Installation Of Butterfly:

Before Installation of “Butterfly” we need to install the “Pip” Tools.


Note- Pip is a tool for installing and managing “Python” packages.

[root@www ~]# curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"


[root@www ~]# python get-pip.py

Verify The Installation


[root@www ~]# pip --help

Check the version of Pip that is installed


[root@www ~]# pip –V
Install Butterfly
[root@www ~]# pip install butterfly

Once you have installed Butterfly on your machine, Now you can check the “Butterfly”
Information.

[root@www ~]# butterfly help

Access your system terminal, from your web browser

Access your terminal from your browser two types:

a- Without SSL (Unsecure)


b- With SSL (Secure)

Without SSL (Unsecure)-


You launch “butterfly.server.py” without generating certificates. So let’s make them!

[root@www ~]# butterfly.server.py --host=172.16.10.7 --port=57575 --login --unsecure


[W 170821 20:15:53 butterfly.server:347] Butterfly is ready, open your browser to:
http://172.16.10.7:57575/
With SSL (Secure)- Generating Certificates Files

In this example I suppose you run the server as root, you want to access it as user “ashu” on a
local network and your ip address on this network is 172.16.10.7:

First generate the root certificate for running on local network.

[root@www ~]# butterfly.server.py --generate-certs --host="172.16.10.7"

# butterfly.server.py --generate-certs --host="172.16.10.7"


Generating certificates for 172.16.10.7 (change it with --host)

Root certificate not found, generating it


Writing /etc/butterfly/ssl/butterfly_ca.crt
Writing /etc/butterfly/ssl/butterfly_ca.key
Writing /etc/butterfly/ssl/butterfly_172.16.10.7.crt
Writing /etc/butterfly/ssl/butterfly_172.16.10.7.key

Now you can run --generate-user-pkcs=user to generate user certificate.

Second Generate PKCS#12 auth file for user foo.

[root@www ~]# butterfly.server.py --generate-user-pkcs=ashu


Reading /etc/butterfly/ssl/butterfly_ca.crt
Reading /etc/butterfly/ssl/butterfly_ca.key

PKCS12 Password (can be blank):


Verify Password (can be blank):

Writing /etc/butterfly/ssl/ashu.p12

[root@www ~]#

Note- If you run as root the certificates will be placed in /etc/buttefly/ssl/, as user in
~/.butterfly/ssl.

[root@www ~]# ll /etc/butterfly/ssl/


-rw------- 1 root root 3616 Aug 21 20:27 ashu.p12
-rw-r--r-- 1 root root 1334 Aug 21 20:25 butterfly_172.16.10.7.crt
-rw------- 1 root root 1704 Aug 21 20:25 butterfly_172.16.10.7.key
-rw-r--r-- 1 root root 1326 Aug 21 20:25 butterfly_ca.crt
-rw------- 1 root root 1704 Aug 21 20:25 butterfly_ca.key

[root@www ~]#
Now certificate has been generated, you will have to configure your browser to accept your self-
signed certificate and the PKCS#12 file (which contains a private key for your user to log in).
Copy “butterfly_ca.crt” and “ashu.p12” to your remote system. where you want to access..

Importing the root certificate in Firefox-

Under Firefox-
First go to Edit > Preferences > Advanced > View Certificates > Authorities > Import… and
specify the “butterfly_ca.crt” file.

Second go to Edit > Preferences > Advanced > View Certificates > Your Certificates> Import…
and specify the “ashu.p12” file.

Now Run The Command @Server

[root@www ~]# butterfly.server.py --host="172.16.10.7"


[W 170821 20:38:03 butterfly.server:347] Butterfly is ready, open your browser to:
https://172.16.10.7:57575/

With login prompt

[root@www ~]# butterfly.server.py --host=172.16.10.7 --port=57575 --login


[W 170821 20:46:37 butterfly.server:347] Butterfly is ready, open your browser to:
https://172.16.10.7:57575/

With Run Command

[root@www ~]# butterfly.server.py --host="172.16.10.7" --cmd="df -h"

[W 170821 20:51:13 butterfly.server:347] Butterfly is ready, open your browser to:


https://172.16.10.7:57575/
With a different port

[root@www ~]# butterfly.server.py --host="172.16.10.7" –port=21190


[W 170821 20:51:13 butterfly.server:347] Butterfly is ready, open your browser to:
https://172.16.10.7:21190/

Run it with system –Linux

[root@www ~]# cd /etc/systemd/system


[root@www system]# curl -O
https://raw.githubusercontent.com/paradoxxxzero/butterfly/master/butterfly.service

% Total % Received % Xferd Average Speed Time Time Time Current


Dload Upload Total Spent Left Speed
100 95 100 95 0 0 123 0 --:--:-- --:--:-- --:--:-- 123

[root@www system]# curl -O


https://raw.githubusercontent.com/paradoxxxzero/butterfly/master/butterfly.socket

% Total % Received % Xferd Average Speed Time Time Time Current


Dload Upload Total Spent Left Speed
100 63 100 63 0 0 80 0 --:--:-- --:--:-- --:--:-- 80
[root@www system]# systemctl enable butterfly.socket

Created symlink from /etc/systemd/system/sockets.target.wants/butterfly.socket to


/etc/systemd/system/butterfly.socket.

[root@www system]# systemctl start butterfly.socket


[root@www system]# systemctl status butterfly.socket

butterfly.socket
Loaded: loaded (/etc/systemd/system/butterfly.socket; enabled; vendor preset:
disabled)
Active: active (listening) since Mon 2017-08-21 20:59:54 IST; 5s ago
Listen: [::]:57575 (Stream)

Aug 21 20:59:54 www.example.com systemd[1]: Listening on butterfly.socket.


Aug 21 20:59:54 www.example.com systemd[1]: Starting butterfly.socket.

[root@www system]#
[root@www ~]# vim /etc/butterfly/butterfly.conf

#Change your server options host, port, shell,..


host='172.16.10.7'
port=57555
shell='/bin/bash'

:wq (Save & Quit)

Restart “butterfly.socket” Services..

[root@www system]# systemctl restart butterfly.socket

Check Log-

[root@www ~]# tail -f /var/log/messages

Aug 21 21:34:36 www butterfly.server.py: socket.error: [Errno 98] Address already in use
Aug 21 21:34:36 www systemd: butterfly.service: main process exited, code=exited,
status=1/FAILURE
Aug 21 21:34:36 www systemd: Unit butterfly.service entered failed state.
Aug 21 21:34:36 www systemd: butterfly.service failed.
Aug 21 21:34:36 www systemd: start request repeated too quickly for butterfly.service
Aug 21 21:34:36 www systemd: Failed to start Butterfly Terminal Server.
Aug 21 21:34:36 www systemd: Unit butterfly.socket entered failed state.
Aug 21 21:34:36 www systemd: butterfly.service failed.
Aug 21 21:37:37 www systemd: Listening on butterfly.socket.
Aug 21 21:37:37 www systemd: Starting butterfly.socket.
Aug 21 21:38:09 www systemd: Started Butterfly Terminal Server.
Aug 21 21:38:09 www systemd: Starting Butterfly Terminal Server...
Aug 21 21:38:09 www butterfly.server.py: [W 170821 21:38:09 butterfly.server:347]
Butterfly is ready, open your browser to: https://172.16.10.7:57555/
Aug 21 21:38:29 www butterfly.server.py: [W 170821 21:38:29 iostream:1327] SSL Error
on 5 ('172.16.10.2', 54291): [SSL: SSLV3_ALERT_BAD_CERTIFICATE] sslv3 alert bad
certificate (_ssl.c:579)

For more information type:

[root@www ~]# butterfly help

-Ashutosh

Reference-

https://github.com/paradoxxxzero/butterfly

You might also like