문제를 보면 단어들이 뒤죽박죽 섞여있으며 순서대로 정렬 후 제출하면 성공합니다.


하지만 시간은 5초만 주어져있고 매번 글자는 랜덤하게 변경됩니다.

 

Coding level이니 만큼 알맞은 코드를 작성해서 전송하면 될것으로 보입니다.



Python을 주로 사용하기에 Python을 이용해서 문제를 풀었습니다.



① Cookie를 이용해 시도

처음에 생각했던 내용은 requests와 BeautifulSoup 모듈을 이용해 해당 페이지에 접근해서 데이터를 가져오는 방법이였습니다.


BeautifulSoup은 HTML과 XML을 파싱하는데 사용됩니다.


다음과 같이 Cookie 값을 이용해서 해당 페이지에 로그인된 상태로 접근하고 데이터를 가져와 전송해봤습니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import requests
from bs4 import BeautifulSoup
 
cookies = {'PHPSESSID':'YourCookie'}    # 본인의 cookie 값 확인
url = 'https://www.hackthis.co.uk/levels/coding/1' 
 
req = requests.post(url, cookies=cookies)    # post 방식으로 cookie값을 가진채 페이지 요청
html = req.text        # 해당 페이지의 모든 html text 불러오기
 
soup = BeautifulSoup(html, 'html.parser')
textarea = soup.find('textarea')    # textarea 태그를 찾기
 
payload = textarea.string.split(', ')
payload.sort()
data = ", ".join(payload)
print(data)
requests.post(url, data=data)
cs



결과는 실패..


생각을 해보니 cookie 값을 가지고 url을 요청하다보면 데이터를 가져올 수 있지만


마지막에 다시 데이터를 보내기위해 requests.post 할 때 새로운 페이지가 열리게 되어 정렬해야할 값이 달라지는 것 같습니다



② selenium를 이용해 시도


브라우져를 컨트롤 할 수 있다는 selenium을 사용해 봤습니다.


submit 버튼을 클릭해야 겠다고 생각하여 버튼 클릭을 할 수 있는 모듈을 찾아보니 selenium으로 가능했습니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from selenium import webdriver
 
url = 'https://www.hackthis.co.uk/levels/coding/1'
path = "chromedriver_win32/chromedriver.exe"    # Chrome Driver File
driver = webdriver.Chrome(path)
 
driver.get(url)
cookie = {'name':'PHPSESSID''value':'YourCookie'}
driver.add_cookie(cookie)
driver.get(url)
 
element = driver.find_element_by_xpath("//textarea")
textarea = element.get_attribute("value")
str(textarea)        # textarea type이 unicode이기에 변경 후 정렬
payload = textarea.split(', ')
payload.sort()
data = ", ".join(payload)
 
 
element = driver.find_element_by_name("answer")
element.send_keys(data)
 
#driver.find_element_by_id('submit').click()
cs


우선 마지막 라인 보시면 주석으로 해놨는데.. 버튼 클릭은 하다가 말았습니다.


대신 아래 사진을보시면 로그인도 잘 수행했으며 Answer에도 정확하게 값이 들어간 걸 확인할 수 있었습니다.


시간도 2초가량 남아서 그대로 그냥 Submit 버튼을 클릭했지만 로딩되는 시간이 길다보니 0초가 되어 성공하지 못했습니다.




③ Session을 이용!!


첫번째 쿠키를 이용했을때 느꼈던건 쿠키를 가지고는 못할 것 같다고 생각했으며


Session을 유지할 수 있다면 가능할 꺼란 생각에 다음과 같이 코등했습니다.


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
import requests
from bs4 import BeautifulSoup
 
url = 'https://www.hackthis.co.uk/levels/coding/1'
 
LOGIN_INFO = {
    'username''YourID',
    'password''YourPWD'
}
 
with requests.Session() as s:
    login_req = s.post('https://www.hackthis.co.uk/?login', data=LOGIN_INFO)
 
    req = s.post(url)
    html = req.text
    soup = BeautifulSoup(html, 'html.parser')
    textarea = soup.find('textarea')
    
    payload = textarea.string.split(', ')
    payload.sort()
    data = ", ".join(payload)
    data = {'answer':data}
    print(data)
    s.post(url, data=data)
 
cs



결론적으로는 성공했으며 Session 유지도 잘 되었고 깔끔하게 되었습니다.


진짜 삽질도 많이했네요 .ㅜㅜ


근데 확인하고 싶은 내용은 ① 에 쿠키를 이용할 때 제가 놓쳤던 부분인데


③의 Line:22를 보시면 data = {'answer':data}를 한게 보일껍니다. 


쿠키를 이용할 때는 그냥 보내면 될꺼라는 생각에 보내기만 했는데 Session 할때 해보니깐


data를 보내도 answer에 적혀있는 데이터여야 정답처리가 된다는 것을 알아기에 다음과 같이 코딩 했습니다.


그런데 이미 completed가 되어 이게 되는지 안되는지 확인을 못하네요 .. ㅜ




[참고]

나만의 웹 크롤러 만들기: https://beomi.github.io/2017/01/20/HowToMakeWebCrawler-With-Login/

문과생도 할 수 있는 웹 크롤링: http://sacko.tistory.com/14?category=643535

Python selenium: https://selenium-python.readthedocs.io/navigating.html?highlight=add_cookie

'WarGame > hackthis.co.uk' 카테고리의 다른 글

[HackThis] Main level7  (0) 2018.08.29
[HackThis] Coding level2  (0) 2018.08.28
[HackThis] Crypt level5  (0) 2018.08.26
[HackThis] Crypt level4  (0) 2018.08.26
[HackThis] Crypt level3  (0) 2018.08.25

Crypt level4 처럼 알고리즘을 알아내지 못하고.. 결국 무자비로 해야했습니다.



우선 형식을 보아하니 뒤집어져 있는거 같습니다.

해석하기 앞서서 문자열을 뒤집어 봅니다.


python으로 간단하게 뒤집을 수 있습니다.



① 'fdcc' == 'pass' 는 확실히 알 수 있는 단어입니다.

a

d

g

 

m


s

c

y


b

 

h

 

n

 

t

 

z


c

 

i

 

o

 

u

 



d

 

j


p

f

v




e

 

k


q

 

w




f


l


r


x




(암호 전/후)


Tls i an a kqinimae. Nt kqinl is ypay oh kzqiosiyt. Nt kqinl is ypay oh bzagimg plopel jt wpay yplt sat ama ypims, moy wpay yplt eoos eisl. Nt kqinl is ypay oh ozysnaqyimg toz, Conlypimg ypay toz wiee mlxlq hoqgixl nl hoq. Jzy ypl pass: YplNlmyoq



② 'plopel' == 'people' 이라는 단어라고 생각됩니다.

'l'은 'e'이고, 'e'는 'l' 라고 생각하고 진행합니다. (이때 암호 문자들이 서로서로 바뀐게 아닐까라는 의심이 되었습니다.)

또한 'o'는 변화가 없는거 같습니다.

a

d

g

 

m


s

c

y


b

 

h

 

n

 

t

 

z


c

 

i

 

o

o

u

 



d

 

j


p

f

v




e

l

k


q

 

w




f


l

e

r


x





python으로 한번에 하고싶은데.. 'l'이랑 'e'가 서로 바뀐거면 애매해져서 손으로 합니다...


Tes i an a kqinimal. Nt kqine is ypay oh kzqiosiyt. Nt kqine is ypay oh bzagimg people jt wpay ypet sat ama ypims, moy wpay ypet loos lise. Nt kqine is ypay oh ozysnaqyimg toz, Coneypimg ypay toz wiee mexeq hoqgixe ne hoq. Jzy ype pass: YpeNemyoq



③ 'Tes' == 'Yes' ▶ 'Nt' == 'My' ▶ 'jt' == 'by'

'Tes'에서 'es'는 이미 변경된 문자고 그렇게 보면 'Yes'라고 판단되고

'Nt'는 'My'가 제일 어울릴 것 같습니다.

'jt'는 'by'가 제일 어울릴 것 같습니다.

(확실한 문자를 풀면 다른 확실한 단어를 찾으면 됩니다)


1:1 대응이라고 생각이되니 진행해 보겠습니다.

a

d

g

 

m

n

s

c

y

t

b

j

h

 

n

m

t

y

z


c

 

i

 

o

o

u

 



d

a

j

b

p

f

v




e

l

k


q

 

w




f


l

e

r


x





Yes i am a kqiminal. My kqime is tpat oh kzqiosity. My kqime is tpat oh jzdging people by wpat tpey say and tpins, not wpat tpey loos lise. My kqime is tpat oh oztsmaqting yoz, Sometping tpat yoz wiee nexeq hoqgixe me hoq. bzt tpe pass: YpeMentoq



④ 'jzdging' == 'judging' / 'Cometping' == 'Something'

'jzdging'에서 'z'만 바뀌지 않았고 사전 검색하니 'judging'라는 단어가 있었습니다.

'Sometping'에서 'p'는 'Something'이라는 말이 어울리므로 다음과 같이 바꿔줍니다.

또한, 'g'와 'i'는 고정인거 같습니다

a

d

g

g

m

n

s

c

y

t

b

j

h

p

n

m

t

y

z

u

c

 

i

i

o

o

u

z



d

a

j

b

p

f

v




e

l

k


q

 

w




f


l

e

r


x





Yes i am a kqiminal. My kqime is that oh kuqiosity. My kqime is that oh judging people by what they say and thins, not what they loos lise. My kqime is that oh outsmaqting you, Something that you will nexeq hoqgixe me hoq. but the pass: TheMentoq



⑤ 'lise' == 'like' / 'outsmaqting' == 'outsmarting' ▶ 'kqime' == 'crime'

a

d

g

g

m

n

s

c

y

t

b

j

h

p

n

m

t

y

z

u

c

k

i

i

o

o

u

z



d

a

j

b

p

f

v




e

l

k

s

q

r

w




f


l

e

r

q

x





Yes i am a criminal. My crime is that oh curiosity. My crime is that oh judging people by what they say and think, not what they look like. My crime is that oh outsmarting you, Something that you will nexer horgixe me hor. but the pass: TheMentor



⑥ 'nexer' == 'never' ▶ 'horgixe' == 'forgive'

a

d

g

g

m

n

s

c

y

t

b

j

h

p

n

m

t

y

z

u

c

k

i

i

o

o

u

z



d

a

j

b

p

f

v

x



e

l

k

s

q

r

w

w



f

h

l

e

r

q

x

v




Yes i am a criminal. My crime is that oh curiosity. My crime is that oh judging people by what they say and think, not what they look like. My crime is that oh outsmarting you, Something that you will never forgive me for. but the pass: TheMentor



문자열을 모두 복호화 했습니다...


몇몇 글자는 변하지 않았으며 대부분의 문자는 대칭을 이루고 있습니다....

(이렇게 하는게 맞는건가요 ㅜㅜ)

'WarGame > hackthis.co.uk' 카테고리의 다른 글

[HackThis] Coding level2  (0) 2018.08.28
[HackThis] Coding level1  (0) 2018.08.28
[HackThis] Crypt level4  (0) 2018.08.26
[HackThis] Crypt level3  (0) 2018.08.25
[HackThis] Crypt level2  (0) 2018.08.25

처음에는 앞선 문제처럼 전치암호로 생각하며 


'Jhll'이 'Pass'라 생각하고 문제를 풀었습니다...


abcdefghijklmnopqrstuvwxyz


'J'와 'P'는 -6글자 차이 (원문을 기준으로)

'h'와 'a'는 +7글자 차이

'l'과 's'는 -7글자 차이

로 정해진 글자수 차이가 아니라 앞선 방법처럼 할 수 없었습니다.



무슨 알고리즘이 있을꺼같아서 계속 고민했지만..... 알아내지 못했고.. ㅜㅜ


하나하나 대응되는 값을 찾기로 생각했습니다.


확실하게 얻을 수 있는 정보부터 차례대로 알아내서 결과를 도출 하면 될 것같습니다.


① 'Jhll' == 'Pass'

a

h

g


m


s

l

y


b


h


n


t


z


c


i


o


u




d


j


p

j

v




e


k


q


w




f


l


r

x




(암호 전/후)


② 'cl' == 'is'

'l' 이 's'로 확정된 이상 'c' 는 'a'아니면 'i'라고 생각한다.

보통 영어 'is'를 많이쓰기에 'is'라고 생각하고 진행해봅니다.

a

h

g


m


s

l

y


b


h


n


t


z


c


i

c

o


u




d


j


p

j

v




e


k


q


w




f


l


r


x





③ 'Gdcl' = 'This'

'cl'이 'is'라고 생각하니 'Gd'는 문장 맨앞에 온다는걸 생각하면 'This'가 맞을 것 같다.

a

h

g


m


s

l

y


b


h

d

n


t

g

z


c


i

c

o


u




d


j


p

j

v




e


k


q


w




f


l


r


x





지금까지 바꾼 문자열은 다음과 같이 된다.

Hi, this is a sirisan ikqa tz sqwqs tuz. This tirq qayh sqttqn is assiomqk a spqyiaiqk nqsatizmship uith amzthqn sqttqn. Pass: ihawqaniqmks


④ 'nqsatizmship' == 'relationship'

솔직히 지금부터는 감으로 찍는게 많았습니다.

'ship'이라는 글자를보고 왠지 'relationship'일꺼라는 생각을 했고 글자수도 마침 딱 맞았습니다.

a

h

g


m


s

l

y


b


h

d

n

m

t

g

z


c


i

c

o

z

u




d


j


p

j

v




e

q

k


q


w




f


l

s

r

n

x





Hi, this is a sirilar ikea to lewel tuo. This tire eayh letter is assionek a speyiaiek relationship uith another letter. Pass: ihawearienkl


점점 눈에 맞아가는 글자들이 보입니다. relationship이 맞는거라고 생각됩니다.


⑤ 'uith' == 'with' / 'eayh' == 'each' / 'tuo' == 'two' / 'lewel' == 'level'

a

h

g


m


s

l

y


b


h

d

n

m

t

g

z


c

y

i

c

o

z

u




d


j


p

j

v

w



e

q

k


q


w

u



f


l

s

r

n

x





Hi, this is a sirilar ikea to level two. This tire each letter is assionek a speciaiek relationship with another letter. Pass: ihavearienkl


⑥ 'assionek' 중에 'o'와 'k'만 바뀌지 않았다.  사전에 검색해보니 'assigned'가 제일 알맞은 단어인것같다.

'sirilar' 중에도 첫번째 'r'만 바뀌지 않았으며. 사전 검색하니 'similar'가 제일 알맞는 단어인것같다.

'speciaiek' 중에도 'k'와 'a'만 바뀌지 않았으며, 'k'는 'd'로 위에서 알았고, 사전 검색하니 'specified'가 제일 알맞다.

a

h

g

o

m

r

s

l

y


b


h

d

n

m

t

g

z


c

y

i

c

o

z

u




d

k

j


p

j

v

w



e

q

k


q


w

u



f

a

l

s

r

n

x





Hi, this is a similar idea to level two. This tire each letter is assigned a specified relationship with another letter. Pass: ihavefriends



야매로 풀은건지... 진짜 제대로된 방법인지는 모르겠는데 일단은.. 해결했습니다. 시간은 오래걸리네요.


python으로 replace하다보면 예를들어 'l'은 's'이고 's'는 'l'이다보니 결국 한 문자로 되서 더 고생한거같아요..ㅜㅜ


다 풀어놓고 다른 사람들은 어떻게 풀었나 봤었는데 크랙 해주는 사이트도 있었네요...

이게 진짜 알고리즘이 없고 이런식으로 뒤죽박죽 만든건지 아니면 알고리즘이 있는데 못찾는건지는 모르겠지만....


혹시나 알고리즘을 발견하신 분은 알려주세요 ㅜㅜ..

'WarGame > hackthis.co.uk' 카테고리의 다른 글

[HackThis] Coding level1  (0) 2018.08.28
[HackThis] Crypt level5  (0) 2018.08.26
[HackThis] Crypt level3  (0) 2018.08.25
[HackThis] Crypt level2  (0) 2018.08.25
[HackThis] Crypt level1  (0) 2018.08.25

+ Recent posts