-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTF_R0_HashMeAgain.py
More file actions
51 lines (39 loc) · 1.35 KB
/
Copy pathCTF_R0_HashMeAgain.py
File metadata and controls
51 lines (39 loc) · 1.35 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
#!/usr/bin/env python
import requests
import hashlib
import urllib2
import re
from lxml import html
import binascii
#Challenge Information
#https://ringzer0ctf.com/challenges/14
#cookie storage
session_name = 'PHPSESSID'
session_value = '<CookieValue>'
#cookie session
session = requests.Session()
jar = requests.cookies.RequestsCookieJar()
jar.set(session_name, session_value)
session.cookies = jar
#request session
inspected_webpage = session.get('https://ringzer0ctf.com/challenges/14/')
#pull webcontent
tree = html.fromstring(inspected_webpage.content)
#scrape everything from class "message"
export_html = tree.xpath('string(//div[@class="message"])')
#Grab message of binary data
#remove spaces and dashes
export_rsad = re.sub("[^a-zA-Z0-9]", "", export_html)
#removing specific words (WORKS BUT REDUNDANT AND SLOPPY!!)
export_rbm = re.sub("BEGINMESSAGE", "", export_rsad)
export_rbem = re.sub("ENDMESSAGE", "", export_rbm)
#Convertion from integer to ASCII
n = int(export_rbem, 2)
binary_ascii = binascii.unhexlify('%x' % n)
#ASCII to Sha512
enc_message = hashlib.sha512(binary_ascii)
enc_output = enc_message.hexdigest()
updated_webpage = session.get('https://ringzer0ctf.com/challenges/14/'+enc_output)
#Extract the flag
final_results = re.findall(r"FLAG.{0,30}", updated_webpage.text)
print(final_results)