Thursday, July 7, 2022

Download Router System Logs using Selenium to Check Intrusions

I have noticed lately that several hacking attempts is being logged by my Globe Home Prepaid Wifi Router. I need to check this every once in a while and thinking that I must record the logs at least once a day and save it to a CSV file for discovering any network intrusions or perhaps discover patterns on the behavior of the attacker.

I prepared a very short python program to automate the downloading process and since I am using windows, I will have to create a scheduled task. If you want to run for yourself, you will need to download the chrodedriver.exe and save it to the directory where the python file is located.

The code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
driver = webdriver.Chrome("chromedriver")
driver.get("http://192.168.254.254/html/overview.html")
driver.find_element(by=By.ID, value="logout_span").click()
# find username/email field and send the username itself to the input field
driver.find_element(by=By.ID, value="username").send_keys('user')
# find password input field and insert password as well
driver.find_element(by=By.ID, value="password").send_keys('########')
# click login button
driver.find_element(by=By.ID, value="pop_login").click()

#driver.find_element(By.LINK_TEXT,'Advance').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT,'Advance'))).click()

#driver.find_element(By.LINK_TEXT,'Advance').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT,'System Logs'))).click()

tbl = driver.find_element(by=By.ID, value="show_log_table").get_attribute('outerHTML')
df  = pd.read_html(tbl)
print(df)

No comments:

Post a Comment