###### tags: `HacktheBox` `Web` # [Web][Hackthebox] Emdee five for life ## 0x01 題目畫面:   題目上要求我們使用MD5去加密第二行的字串 如果這題能夠這麼輕鬆的話有多好 於是我把上面那串De0wJfnprd4BxvaJBKmj去做MD5 ==a45ad13a94dbea8c541914bcd3821bc0==  他回我Too Slow ... 看來手動去加密絕對是不夠快的,而且每次刷新網頁都會給不同的字串 ## 0x02 題目觀測完了,接下來就是寫一支程式讓他解答了 ! 這裡我會順便提供BeautifulSoup和re的寫法 * 第一種: * BeautifulSoup * requests * hashlib * 第二種: * re * requests * hashlib 第一種寫法 === 1. 先把所有需要用到的module先引入。 ``` from bs4 import BeautifulSoup import requests import hashlib ``` 2. 利用requests去請求網頁的原始碼,且因為待會還要將答案送出去所以要利用session()。 * code: ``` url = 'http://178.128.40.217:31528' # 題目網址 requests = requests.session() res = requests.get(url) print(res.text) ``` * output: ``` <html> <head> <title>emdee five for life</title> </head> <body style="background-color:powderblue;"> <h1 align='center'>MD5 encrypt this string</h1><h3 align='center'>vgWs5izaLhTwjRBK3erm</h3><center><form action="" method="post"> <input type="text" name="hash" placeholder="MD5" align='center'></input> </br> <input type="submit" value="Submit"></input> </form></center> </body> </html> ``` 可以看到我們要的資訊就是```<h3 align='center'>vgWs5izaLhTwjRBK3erm</h3>``` 而BeautifulSoup方便的部分就是不用正則表達式就可以撈出h3的內容。 3. 利用BeautifulSoup的函式取得我們要做hash的字串。 * code: ``` bs = BeautifulSoup(res.text,'html.parser') plaintext = bs.find('h3').getText() print(f'Plaintext : {plaintext}') ``` * output: ``` Plaintext : vgWs5izaLhTwjRBK3erm ``` 4. 使用hashlib提供的md5 function來對字串做hash。 * code: ``` plaintext = plaintext.encode('utf8') m = hashlib.md5() m.update(plaintext) ciphertext = m.hexdegist() print(f'Ciphertext: {ciphertext}') ``` * output: ``` Ciphertext : ed5d5bf39d04a6546500da9632c74156 ``` 5. 將Ciphertext作為解答送出,並印出結果; 在這裡我們要先檢查網頁的傳輸模式(GET/POST),以及輸入框的name。  * Info: * Method= =="post"== * input name= =="hash"== * code: ``` data = {"hash":ciphertext} answer = requests.post(url=url,data=data) print(answer.text) ``` * output: ``` <html> <head> <title>emdee five for life</title> </head> <body style="background-color:powderblue;"> <h1 align='center'>MD5 encrypt this string</h1><h3 align='center'>6x0oGPQFfNzQeVhlUem6</h3> <p align='center'>HTB{N1c3_ScrIpt1nG_B0i!}</p><center><form action="" method="post"> <input type="text" name="hash" placeholder="MD5" align='center'></input> </br> <input type="submit" value="Submit"></input> </form></center> </body> </html> ``` 登愣!Get the Flag ```HTB{N1c3_ScrIpt1nG_B0i!}``` 第二種寫法 === 1. 先把所有需要用到的module先引入。 ``` import re import requests import hashlib ``` 2. 利用requests去請求網頁的原始碼,且因為待會還要將答案送出去所以要利用session()。 * code: ``` url = 'http://178.128.40.217:31528' # 題目網址 requests = requests.session() res = requests.get(url) print(res.text) ``` * output: ``` <html> <head> <title>emdee five for life</title> </head> <body style="background-color:powderblue;"> <h1 align='center'>MD5 encrypt this string</h1><h3 align='center'>vgWs5izaLhTwjRBK3erm</h3><center><form action="" method="post"> <input type="text" name="hash" placeholder="MD5" align='center'></input> </br> <input type="submit" value="Submit"></input> </form></center> </body> </html> ``` 可以看到我們要的資訊就是```<h3 align='center'>vgWs5izaLhTwjRBK3erm</h3>``` 接下來就是利用正則表達式將h3的內容爬出來了! 3. 利用re.findall搭配正則爬出我們需要的資訊。 * code: ``` plaintext = re.findall(r"<h3 align='center'>(.*?)<",res.text)[0] print(f'Plaintext : {plaintext}') ``` * output: ``` Plaintext : vgWs5izaLhTwjRBK3erm ``` 4. 使用hashlib提供的md5 function來對字串做hash。 * code: ``` plaintext = plaintext.encode('utf8') m = hashlib.md5() m.update(plaintext) ciphertext = m.hexdegist() print(f'Ciphertext: {ciphertext}') ``` * output: ``` Ciphertext : ed5d5bf39d04a6546500da9632c74156 ``` 5. 將Ciphertext作為解答送出,並印出結果; 在這裡我們要先檢查網頁的傳輸模式(GET/POST),以及輸入框的name。  * Info: * Method= =="post"== * input name= =="hash"== * code: ``` data = {"hash":ciphertext} answer = requests.post(url=url,data=data) print(answer.text) ``` * output: ``` <html> <head> <title>emdee five for life</title> </head> <body style="background-color:powderblue;"> <h1 align='center'>MD5 encrypt this string</h1><h3 align='center'>6x0oGPQFfNzQeVhlUem6</h3> <p align='center'>HTB{N1c3_ScrIpt1nG_B0i!}</p><center><form action="" method="post"> <input type="text" name="hash" placeholder="MD5" align='center'></input> </br> <input type="submit" value="Submit"></input> </form></center> </body> </html> ``` 登愣!Get the Flag ```HTB{N1c3_ScrIpt1nG_B0i!}```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up