Last active
August 24, 2022 07:31
-
-
Save vinhjaxt/1b78c1d798dc378814b93b6e02f04501 to your computer and use it in GitHub Desktop.
Tạo CTFd Users hàng loạt và in giấy thông tin đăng nhập
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/user/bin/env python3 | |
# pip install passlib==1.7.2 bcrypt==3.1.7 | |
# https://github.com/CTFd/CTFd/blob/master/requirements.in | |
# passlib==1.7.2 | |
# bcrypt==3.1.7 | |
import hashlib | |
from passlib.hash import bcrypt_sha256 | |
import copy | |
import json | |
import string | |
import random | |
## Chuyển Tiếng Việt | |
import re | |
def no_accent_vietnamese(s): | |
s = re.sub(u'[àáạảãâầấậẩẫăằắặẳẵ]', 'a', s) | |
s = re.sub(u'[ÀÁẠẢÃĂẰẮẶẲẴÂẦẤẬẨẪ]', 'A', s) | |
s = re.sub(u'[èéẹẻẽêềếệểễ]', 'e', s) | |
s = re.sub(u'[ÈÉẸẺẼÊỀẾỆỂỄ]', 'E', s) | |
s = re.sub(u'[òóọỏõôồốộổỗơờớợởỡ]', 'o', s) | |
s = re.sub(u'[ÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠ]', 'O', s) | |
s = re.sub(u'[ìíịỉĩ]', 'i', s) | |
s = re.sub(u'[ÌÍỊỈĨ]', 'I', s) | |
s = re.sub(u'[ùúụủũưừứựửữ]', 'u', s) | |
s = re.sub(u'[ƯỪỨỰỬỮÙÚỤỦŨ]', 'U', s) | |
s = re.sub(u'[ỳýỵỷỹ]', 'y', s) | |
s = re.sub(u'[ỲÝỴỶỸ]', 'Y', s) | |
s = re.sub(u'[Đ]', 'D', s) | |
s = re.sub(u'[đ]', 'd', s) | |
return s | |
## /Chuyển Tiếng Việt | |
def id_generator(size=8, chars=string.ascii_uppercase + string.digits): | |
return ''.join(random.choice(chars) for _ in range(size)) | |
def hash_password(plaintext): | |
return bcrypt_sha256.hash(str(plaintext)) | |
user_default = json.loads(u'{"id":2,"oauth_id":null,"name":"demo","password":"$bcrypt-sha256$2b,12$JuvYngfN5T/vG2Yz16rPT.$r5/AieQ2sHc05sWStVeWGI49.03iO7C","email":"[email protected]","type":"user","secret":null,"website":null,"affiliation":null,"country":"VN","bracket":null,"hidden":0,"banned":0,"verified":1,"team_id":null,"created":"2022-04-24T03:39:07"}') | |
dashboard_url = 'http://x.x.x.x:8000' | |
email_domain = '@dientap.local' | |
names = re.split(r'[\r\n]+', u''' | |
Đội 1 | |
Đội 2 | |
Đội 3 | |
Đội 4 | |
''') | |
start_id = 1 | |
users = [] | |
for name in names: | |
user_name = name.strip() | |
if len(user_name) == 0: | |
continue | |
user_name = re.sub(r'\s+', '', user_name) | |
start_id += 1 | |
user_name = no_accent_vietnamese(user_name).lower() | |
user_name = re.sub(r'[^A-Za-z0-9_\-\.]+', '', user_name) | |
password = id_generator() | |
user = copy.deepcopy(user_default) | |
user['id'] = start_id | |
user['password'] = hash_password(password) | |
user['name'] = name | |
user['email'] = user_name+email_domain | |
user['verified'] = 1 | |
user['country'] = 'VN' | |
users.append(user) | |
print() | |
print(name) | |
print('Địa chỉ:', dashboard_url) | |
print('Tên đăng nhập:', user['email']) | |
print('Mật khẩu:', password) | |
print() | |
print(json.dumps(users)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm i -g docx-templates | |
const fs = require('fs') | |
const createReportDocx = require('docx-templates').default | |
const templateFile = 'ctf_users_template.docx' | |
async function getDocx(users) { | |
const buf = await createReportDocx({ | |
noSandbox: false, | |
template: fs.readFileSync(templateFile), | |
data: { | |
users, | |
}, | |
additionalJsContext: { | |
getUsers: () => Promise.resolve(users), | |
} | |
}) | |
return buf | |
} | |
getDocx([`Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: 2TB1ZLIB`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: NCEFM6MU`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: L9PKBRU0`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: 9IXOGXN2`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: HIB3WVSH`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: GSSH0KQX`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: Y4TFD0AJ`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: F3C733I2`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: 9IQ2JK18`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: HI3G4R6K`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: ZMOPNKW7`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: 9AE8DOP7`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: D6AX00HE`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: 5ZY6G5NL`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: 4ZS84P6I`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: WJ6F3K2M`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: P6K2AMCC`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: Z5NB2GOP`, `Đội XXXX | |
Địa chỉ: http://x.x.x.x | |
Tên đăng nhập: [email protected] | |
Mật khẩu: 38825UHV`]).then(buf => { | |
fs.writeFileSync('ctfd_users.docx', buf) | |
}).catch(console.error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proxy_set_header Host $http_host; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"count":1,"results":[{"id":1,"challenge_id":1,"type":"regex","content":"123123123","data":"case_insensitive"}],"meta":{}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment