Skip to content

Instantly share code, notes, and snippets.

@neilchetty
Last active October 15, 2023 02:28
Show Gist options
  • Save neilchetty/bc2982909d54fb95a567578ce525c9a5 to your computer and use it in GitHub Desktop.
Save neilchetty/bc2982909d54fb95a567578ce525c9a5 to your computer and use it in GitHub Desktop.
SonicFireWall Login
# Latest python version is needed
# Latest firefox version is needed
# Selenium package is needed please install by running:
# pip install selenium
# If driver cannot be located please refer this:
# https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from urllib.request import urlopen
import sys
import time
import os
USERNAME = 'ENTER_USERNAME_HERE'
PASSWORD = 'ENTER_PASSWORD_HERE'
AUTH_URL = "https://172.16.16.1/auth1.html"
NCSI_URL = "http://www.msftncsi.com/ncsi.txt"
def check_for_active_internet():
try:
response = urlopen(NCSI_URL)
source = response.read()
if len(source) == 14:
return True
else:
return False
except:
return False
def main() :
os.environ['MOZ_HEADLESS'] = '1'
driver = webdriver.Firefox()
driver.set_window_size(100,100)
driver.set_page_load_timeout(15)
print ("\n[*] Opening a New Session")
try :
driver.get(AUTH_URL)
except TimeoutException:
print ("\n[!] Target can't be reached. Are you on the right WiFi/LAN? \n")
driver.quit()
return
assert "Sonic" in driver.title
print ("\n[*] Enumerating Login Page")
user = driver.find_element(By.NAME, 'userName')
passwd = driver.find_element(By.NAME, 'pwd')
print ("\n[*] Sending Credentials")
user.send_keys(USERNAME)
passwd.send_keys(PASSWORD)
passwd.send_keys(Keys.RETURN)
time.sleep(3)
driver.get(NCSI_URL)
if not check_for_active_internet():
print ("\n[!] Could not Login! Invalid Credentials? \n")
driver.quit()
return 1
print ("\n[*] Login Done! Will repeat every 2 hour, to cancel press ctrl+c \n")
driver.quit()
time.sleep((60*60*2)-10)
while True :
try :
error_value = main()
if error_value == 1 :
break
except KeyboardInterrupt:
print ("\n[*] Enough Internet for Today! \n")
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment