-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctfd-auto-backup.py
47 lines (34 loc) · 1.4 KB
/
ctfd-auto-backup.py
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
import requests, wget, os, time
from bs4 import BeautifulSoup
from datetime import datetime
timestmp = str(datetime.now().replace(microsecond=0))
headers = {
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Referer': 'http://urctfd.domain/admin/config',
'Accept-Language': 'en-US,en;q=0.9,id;q=0.8',
}
s = requests.Session()
url = "http://urctfd.domain/login"
r = s.get(url)
soup = BeautifulSoup(r.content, "html.parser")
nonce = soup.find("input",{"name":"nonce"})['value']
data = {
'name': 'yourCTFdAdmin',
'password': '*****',
'_submit': 'Submit',
'nonce': nonce
}
print('Logging in to '+url+' . .')
s.post(url, data=data, allow_redirects=True)
cookies = s.cookies.get_dict()
print('Downloading the file . .')
backup = requests.get('http://urctfd.domain/admin/export', headers=headers, cookies=cookies, allow_redirects=True, stream=True)
path = 'backup_dir/'
file_name = os.path.join(path, 'ctfd_backup'+timestmp+'.zip')
if not os.path.exists(path):
os.makedirs(path)
open(file_name, 'wb').write(backup.content)
print('Successfully Exported ['+file_name+']')