-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
78 lines (63 loc) · 1.86 KB
/
client.py
File metadata and controls
78 lines (63 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python
import signal
import time
import os
from selenium import webdriver
def test_request(arg=None):
"""Your http request."""
time.sleep(2)
return arg
class Timeout():
"""Timeout class using ALARM signal."""
class Timeout(Exception):
pass
def __init__(self, sec):
self.sec = sec
def __enter__(self):
signal.signal(signal.SIGALRM, self.raise_timeout)
signal.alarm(self.sec)
def __exit__(self, *args):
signal.alarm(0) # disable alarm
def raise_timeout(self, *args):
raise Timeout.Timeout()
# performing login action
def site_login():
# initialize chrome browser
driver = webdriver.Chrome()
# going to the website that vulnerable to XSS and perfroming certain actions
# example is a XSS challenge in CSA CTF 2019
driver.get("http://35.231.36.102:1779/login.php")
driver.find_element_by_name("username").send_keys("admin")
driver.find_element_by_name("password").send_keys("verysecuredpassword")
driver.find_element_by_name("submit").click()
# accepting any alert that pops up
while True:
try:
alert = driver.switch_to_alert()
alert.accept()
time.sleep(0.5)
except:
break
# maintaing the session for 2 minutes
time.sleep(120)
# clicking logout
driver.get("http://35.231.36.102:1779/logout.php")
# closing browser normally
driver.quit()
i = 0
while True:
try:
# timer
with Timeout(180):
site_login()
print i, "Logged in."
# force close the browser after some time.
except Timeout.Timeout:
pass
os.system("pkill chromium-browser")
print i, "Timeout"
except:
pass
os.system("pkill chromium-browser")
print i, "Failed for some reason"
i += 1