Skip to content

Instantly share code, notes, and snippets.

@d4em0n
Last active October 6, 2018 03:13
Show Gist options
  • Save d4em0n/e77cd4ec211d439cc6cf46a7e3afd805 to your computer and use it in GitHub Desktop.
Save d4em0n/e77cd4ec211d439cc6cf46a7e3afd805 to your computer and use it in GitHub Desktop.
CTFd auto submit
from bs4 import BeautifulSoup
import requests
import json
url = "https://ctf.asgama.web.id"
class CTFDAutoSubmit:
nonce_submit = 0
def __init__(self, url, user, pasw):
self.ctf = requests.Session()
self.url = url
if not self.login(user, pasw):
raise Exception("Login gagal")
def login(self, user, pasw):
r = self.ctf.get(self.url + "/login")
datalogin = dict(name=user, password=pasw)
data = r.content
soup = BeautifulSoup(data, 'html.parser')
nonce = soup.find('input', {'name':'nonce'}).get('value')
datalogin["nonce"] = nonce
r = self.ctf.post(self.url + "/login", data=datalogin)
return "Your username or password is incorrect" not in r.text
def submit(self, chal_id, flag):
datasub = dict(key=flag)
if self.nonce_submit == 0:
r = self.ctf.get(self.url + "/challenges")
data = r.content
soup = BeautifulSoup(data, 'html.parser')
self.nonce_submit = soup.find('input', {'name':'nonce'}).get('value')
datasub["nonce"] = self.nonce_submit
r = self.ctf.post("{}/chal/{}".format(self.url, chal_id), data=datasub)
return json.loads(r.text)
def main():
ctfd = CTFDAutoSubmit(url, "[email protected]", "kkk")
s = ctfd.submit(28, "GamaCTF{t1s_pR0b_iS_Tuuu_3z}")
print(s["message"])
s = ctfd.submit(27, "GamaCTF{t1s_pR0b_iS_Tuuu_3z}")
print(s["message"])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment