Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Last active February 20, 2023 03:02
Show Gist options
  • Save gilangvperdana/6ced82adc74ed79fa5ac5d7091e991a9 to your computer and use it in GitHub Desktop.
Save gilangvperdana/6ced82adc74ed79fa5ac5d7091e991a9 to your computer and use it in GitHub Desktop.
Auto Login Internet Landing Page with Google Chrome Headless and Runing it on Container

Goals

  • Can auto login loginpage of internet provider with CLI (Ubuntu Server)
  • Can auto login when ping to 1.1.1.1 down detected (RTO)
  • Can auto login with simplicity (not use payload/etc cause this parameter is hard to understand)

WARN

  • This technique use headless browser, so you must login it first with google-chrome GUI with X11 or anything then you can move that cookies data to container
  • Coockies data used for headless browser to know about historical our saved credentials
    • We must create cache first on our host to create /root/.config/google-chrome/ directory for cookies
    • Simple, we must manual login with X11 forwarding first on somewhere VM then we can use cache from our host directory to our container then,
    • Flow : Install google-chrome on host first -> launch it -> login then save -> copy cache directory to container
  • This case use 2 different WAN, who WAN1 not need login but on WAN2 as failover need to login first
    • So, i will use IPVLAN for my Container cause i need to configure some IP endpoint on my router to use PBR (Policy Based Routing)
    • Assume on my case, i configure 172.20.1.194 ip always use gateway WAN2 with PBR on my router
    • In my case, i user Mikrotik for PBR configuration like this :
      /ip firewall address-list
      add list=special-clients address=172.20.1.194
      
      /ip firewall mangle
      add chain=prerouting src-address-list=special-clients action=mark-routing new-routing-mark=special-routing
      
      /ip route
      add dst-address=0.0.0.0/0 gateway=10.20.0.1 routing-mark=special-routing
      
      # Default route `to 192.168.69.1` all of client except `172.20.1.194`
      /ip route
      add dst-address=0.0.0.0/0 gateway=192.168.69.1
      

Prerequisites

  • Ubuntu Server
    • Google Chrome
    • Docker

Create Script

#!/bin/bash

# Inisialisasi variabel
max_rto=5 # jumlah RTO maksimum sebelum membuka website
rto_count=0 # jumlah RTO saat ini

# Loop forever
while true
do
    # Ping ke 1.1.1.1 sebanyak satu kali dengan timeout 1 detik
    ping -c 1 -W 1 1.1.1.1 > /dev/null

    # Jika ping mengalami RTO
    if [ $? -ne 0 ]
    then
        rto_count=$((rto_count+1)) # tambahkan jumlah RTO saat ini

        # Jika jumlah RTO saat ini sama dengan jumlah RTO maksimum
        if [ $rto_count -eq $max_rto ]
        then
            # Menampilkan pesan
            echo "Jumlah RTO mencapai batas maksimum. Membuka website."

            # Menjalankan Google Chrome headless dan membuka website tertentu
            timeout 100 google-chrome --headless --user-data-dir=/root/.config/google-chrome/ --disable-gpu --remote-debugging-port=9222 --no-sandbox --disable-setuid-sandbox "https://login.isp.com"

            # Reset jumlah RTO saat ini
            rto_count=0
        fi
    else
        # Reset jumlah RTO saat ini jika ping berhasil
        rto_count=0
    fi

    # Menunggu selama 10 detik sebelum melakukan ping lagi
    sleep 10
done

Create Dockerfile & Build Image

# Gunakan base image ubuntu 20.04
FROM ubuntu:20.04

# Update package list dan install paket yang dibutuhkan
RUN apt-get update && \
    apt-get install gnupg -y && \
    apt-get install wget -y && \
    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
    sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
    apt-get update -y && \
    apt-get install -y curl net-tools iputils-ping google-chrome-stable

# Copy script ke dalam container
COPY script.sh /usr/local/bin/

# Berikan permission untuk menjalankan script
RUN chmod +x /usr/local/bin/script.sh

# Jalankan script pada saat container di-start
CMD ["script.sh"]

Create IP VLAN

docker network create -d ipvlan \
--subnet 172.20.0.0/16 \
--gateway 172.20.0.1 \
-o parent=bond0 \
WAN2PBR

Run Container

docker run -d --restart always --network WAN2PBR --ip 172.20.1.194 --name inetautologin $DOCKER_IMAGE

Copy our cache directory from host to container

docker cp /root/.config/google-chrome inetautologin:/root/.config/

Then, enjoy~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment