반응형
반응형
반응형

client ip와 agent 정보를 확인할 수 있고

 

아래에는 wrong IP라고 적혀 있다. 일단 ip값을 맞추면 되는 문제라고 추측해볼 수 있다.

 

 

소스를 보자.

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
<?php
  include "../../config.php";
  if($_GET['view_source']) view_source();
?><html>
<head>
<title>Challenge 24</title>
</head>
<body>
<p>
<?php
  extract($_SERVER);
  extract($_COOKIE);
  $ip = $REMOTE_ADDR;
  $agent = $HTTP_USER_AGENT;
  if($REMOTE_ADDR){
    $ip = htmlspecialchars($REMOTE_ADDR);
    $ip = str_replace("..",".",$ip);
    $ip = str_replace("12","",$ip);
    $ip = str_replace("7.","",$ip);
    $ip = str_replace("0.","",$ip);
  }
  if($HTTP_USER_AGENT){
    $agent=htmlspecialchars($HTTP_USER_AGENT);
  }
  echo "<table border=1><tr><td>client ip</td><td>{$ip}</td></tr><tr><td>agent</td><td>{$agent}</td></tr></table>";
  if($ip=="127.0.0.1"){
    solve(24);
    exit();
  }
  else{
    echo "<hr><center>Wrong IP!</center>";
  }
?><hr>
<a href=?view_source=1>view-source</a>
</body>
</html>
cs

 

$ip가 127.0.0.1이 되면 문제가 풀린다.

 

extract 함수는 배열의 키값을 변수화 시켜주는 함수이다. 12행에 extract($_COOKIE); 가 있기 때문에

cookie에 REMOTE_ADDR="abcd"를 넣어주면, $REMOTE_ADDR의 값이 "abcd"가 되어 13행에서 $ip에 "abcd"값이 들어가게 된다.

 

17~20행에서 특정 문자열이 치환되는 것을 고려하여 결과가 127.0.0.1이 되는 입력값은 112277...00...00...1 이다.

 

따라서 쿠키에 REMOTE_ADDR라는 이름에 값을 112277...00...00...1으로 설정해주면 된다.

반응형
반응형

 

 

 

문제 페이지로 접속을 하면 소스를 볼 수 있는 링크가 있으며, idpw가 적혀 있다.

 

 

view-source를 클릭하여 소스코드를 확인하자.

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
<?php
include "../../config.php";
if($_GET['view_source']) view_source();
if(!$_COOKIE['user']){
  $val_id="guest";
  $val_pw="123qwe";
  for($i=0;$i<20;$i++){
    $val_id=base64_encode($val_id);
    $val_pw=base64_encode($val_pw);
  }
  $val_id=str_replace("1","!",$val_id);
  $val_id=str_replace("2","@",$val_id);
  $val_id=str_replace("3","$",$val_id);
  $val_id=str_replace("4","^",$val_id);
  $val_id=str_replace("5","&",$val_id);
  $val_id=str_replace("6","*",$val_id);
  $val_id=str_replace("7","(",$val_id);
  $val_id=str_replace("8",")",$val_id);
 
  $val_pw=str_replace("1","!",$val_pw);
  $val_pw=str_replace("2","@",$val_pw);
  $val_pw=str_replace("3","$",$val_pw);
  $val_pw=str_replace("4","^",$val_pw);
  $val_pw=str_replace("5","&",$val_pw);
  $val_pw=str_replace("6","*",$val_pw);
  $val_pw=str_replace("7","(",$val_pw);
  $val_pw=str_replace("8",")",$val_pw);
 
  Setcookie("user",$val_id,time()+86400,"/challenge/web-06/");
  Setcookie("password",$val_pw,time()+86400,"/challenge/web-06/");
  echo("<meta http-equiv=refresh content=0>");
  exit;
}
?>
<html>
<head>
<title>Challenge 6</title>
<style type="text/css">
body { background:black; color:white; font-size:10pt; }
</style>
</head>
<body>
<?php
$decode_id=$_COOKIE['user'];
$decode_pw=$_COOKIE['password'];
 
$decode_id=str_replace("!","1",$decode_id);
$decode_id=str_replace("@","2",$decode_id);
$decode_id=str_replace("$","3",$decode_id);
$decode_id=str_replace("^","4",$decode_id);
$decode_id=str_replace("&","5",$decode_id);
$decode_id=str_replace("*","6",$decode_id);
$decode_id=str_replace("(","7",$decode_id);
$decode_id=str_replace(")","8",$decode_id);
 
$decode_pw=str_replace("!","1",$decode_pw);
$decode_pw=str_replace("@","2",$decode_pw);
$decode_pw=str_replace("$","3",$decode_pw);
$decode_pw=str_replace("^","4",$decode_pw);
$decode_pw=str_replace("&","5",$decode_pw);
$decode_pw=str_replace("*","6",$decode_pw);
$decode_pw=str_replace("(","7",$decode_pw);
$decode_pw=str_replace(")","8",$decode_pw);
 
for($i=0;$i<20;$i++){
  $decode_id=base64_decode($decode_id);
  $decode_pw=base64_decode($decode_pw);
}
 
echo("<hr><a href=./?view_source=1 style=color:yellow;>view-source</a><br><br>");
echo("ID : $decode_id<br>PW : $decode_pw<hr>");
 
if($decode_id=="admin" && $decode_pw=="nimda"){
  solve(6);
}
?>
</body>
</html>
cs

 

4~33행은 cookie에 user값이 없으면, id와 pw를 각각 guest, 123qwe로 두고 인코딩하여 쿠키값을 설정하는 과정이고, 44~68행은 설정된 user와 password 쿠키값을 디코딩하는 과정이다.

 

73행에서는 디코딩된 id와 pw값이 각각 admin, nimda라면 문제가 풀리는 것을 알 수 있다.

 

 

인코딩 과정을 보면, 먼저 평문을 base64로 20번 인코딩하고 str_replace함수로 문자를 치환한다.

 

이 과정을 그대로 python으로 작성하여 id와 pw를 admin과 nimda로 두면 인코딩된 쿠키값을 얻을 수 있다.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import base64
 
def enc(value):
  for i in range(20):
      value = str(base64.b64encode(bytes(value)))
  value = value.replace("1","!")
  value = value.replace("2","@")
  value = value.replace("3","$")
  value = value.replace("4","^")
  value = value.replace("5","&")
  value = value.replace("6","*")
  value = value.replace("7","(")
  value = value.replace("8",")")
 
  return value
 
id = "admin"
pw = "nimda"
 
print(enc(id) + "\n\n")
print(enc(pw))
 
cs

 

 

실행 결과:

 

 

쿠키 값 설정은 크롬 확장프로그램 중에서 editthiscookie를 사용했다.

 

설정 후 페이지를 새로고침하면 문제가 풀린다.

반응형
반응형

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
반응형

네이버 카페의 글 제목, 작성자 닉네임, 작성일을 파싱하는 코드입니다.

 

 

 

로그인 절차가 필요 없습니다.

 

게시판 페이지를 파싱합니다.

 

게시판 링크는 게시판 링크 우클릭해서 링크 복사 해서 /ArticleList.nhn 부분부터 복사하여

카페 링크 뒤에 붙이시면 됩니다.

 

 

 

추가 인자값들은 아래 코드에서 확인하세요. (userDisplay 이나 search.page 등)

 

 

 

 

simple_html_dom.php 파일을 필요로 합니다:

https://simplehtmldom.sourceforge.io/

 

PHP Simple HTML DOM Parser

$html = str_get_html(' Hello World '); $html->find('div', 1)->class = 'bar'; $html->find('div[id=hello]', 0)->innertext = 'foo'; echo $html; $html = file_get_html('http://slashdot.org/'); foreach($html->find('div.article') as $article) {     $item['title']

simplehtmldom.sourceforge.io

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
<?php
/*ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);*/
 
include($_SERVER['DOCUMENT_ROOT'].'simple_html_dom.php');
//simple_html_dom.php 파일 수정 필요합니다.
//https://mandu-mandu.tistory.com/358
 
 
function naver_cafe_article_parser($page_no){
  //작성자 M4ndU
 
  //카페 url
  //카페 링크 aaaaa처리
  //search.clubid, search.menuid 0 처리
  //하였기 때문에 본인 카페 링크및 게시판 확인하셔서 변경하셔야합니다.
  $url = "https://cafe.naver.com/aaaaa/ArticleList.nhn?search.clubid=000000000&search.boardtype=L&search.menuid=00&search.marketBoardTab=D%&search.specialmenutype=&userDisplay=50&search.page=".$page_no;
 
  $html = file_get_html($url);
 
  $board = $html->find('div[class=article-board m-tcol-c]');
  foreach ($board[1]->find('tr'as $article) {
 
    $article_title_link = $article->find('a[class=article]')[0];
    $article_title = $article_title_link->plaintext;
    $article_link = $article_title_link->href;
    $article_publisher = $article->find('td[class=p-nick]')[0]->plaintext;
    $article_date = $article->find('td[class=td_date]')[0]->innertext;
 
    if ($article_title == "") {
      continue;
    }
 
 
    echo "<tr>";
    echo "<td>".$article_title."</td>";
    echo "<td>".$article_publisher."</td>";
    echo "<td>".$article_date."</td>";
    echo "<td> https://cafe.naver.com/aaaaa".$article_link."</td>"//카페링크 aaaaa처리하였음. 본인이 변경하세요.
    echo "</tr>";
  }
}
?>
<!DOCTYPE html>
<html lang="kr" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <table class="table">
        <thead>
            <th>글제목</th>
            <th>작성자</th>
            <th>등록일시</th>
            <th>링크</th>
        </thead>
<?php
for ($i=1$i<10 ; $i++) { // 파싱할 게시판의 최대 페이지를 고려하세요.
  naver_cafe_article_parser($i);
}
?>
</table>
</body>
</html>
 
cs
반응형
반응형

strcmp

if you can bypass the strcmp function, you get the flag.

 

 

 

password를 입력받는 칸과 소스를 확인할 수 있는 링크가 있다.

 

일단 소스코드를 확인해 보자.

 

 

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
<?php
    require("../lib.php"); // for auth_code function
 
    $password = sha1(md5(rand().file_get_contents("/var/lib/dummy_file")).rand());
 
    if (isset($_GET['view-source'])) {
        show_source(__FILE__);
        exit();
    }else if(isset($_POST['password'])){
        sleep(1); // do not brute force!
        if (strcmp($_POST['password'], $password== 0) {
            echo "Congratulations! Flag is <b>" . auth_code("strcmp") ."</b>";
            exit();
        } else {
            echo "Wrong password..";
        }
    }
 
?>
<br />
<br />
<form method="POST">
    password : <input type="text" name="password" /> <input type="submit" value="chk">
</form>
<br />
<a href="?view-source">view-source</a>
cs

 

 

$password sha1(md5(rand().file_get_contents("/var/lib/dummy_file")).rand());

 

$password는 랜덤 값의 sha1 해쉬값이다. 따라서 때려맞출 수는 없다.

 

 

 

 

대신 strcmp함수의 취약점을 이용하면 된다.

 

strcmp(String, Array()) 는 NULL을 반환한다.

 

php에서 NULL == 0 은 True가 된다.

 

 

 

 

 

 

따라서 password를 배열로 보내면 flag를 얻을 수 있게 된다.

 

크롬 개발자 도구를 이용해서 password를 password[]로 바꾼 뒤에 아무 값이나 입력해서 보내면, flag를 얻을 수 있다.

반응형

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

Wargame.kr [fly me to the moon] 풀이  (0) 2019.12.24
Wargame.kr [DB is really GOOD] 풀이  (0) 2019.12.24
Wargame.kr [fly me to the moon] 풀이  (0) 2019.12.23
Wargame.kr [md5 password] 풀이  (0) 2019.08.22
Wargame.kr [WTF_CODE] 풀이  (0) 2019.08.22
반응형

문제소스 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect();
  $_GET['id'= strrev(addslashes($_GET['id']));
  $_GET['pw'= strrev(addslashes($_GET['pw']));
  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_zombie_assassin 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']) solve("zombie_assassin"); 
  highlight_file(__FILE__); 
?>
cs

 

 

 

  $_GET['id'] = strrev(addslashes($_GET['id']));
  $_GET['pw'] = strrev(addslashes($_GET['pw']));

 

idpwaddslashes로 아래 문자에 \을 붙여준다. https://www.w3schools.com/php/func_string_addslashes.asp

  • single quote (')
  • double quote (")
  • backslash (\)
  • NULL (%00)

그리고 strrev으로 문자열을 뒤집는다.

 

 

 

 

이전 문제처럼 쿼리에서 id = ' 부터 pw =' 까지를 문자열 취급하게 만들면 될 것 같다.

https://mandu-mandu.tistory.com/315

 

 

 

 

 

id='' and pw=''

두번째 싱글쿼트 앞에 \가 붙게 하여 문자열 취급하도록 해야 한다.

 

 

 

 

id에 \와 '을 제외한 나머지 " 또는 NULL (%00)을 넣어보자

 

" -> \" -> "\

id='"\' and pw = ''

 

\가 뒤로 오면서 '가 문자열 취급되고, " ' 안에 있기 때문에 문자열 취급된다.

 

 

 

 

 

이제 pw=' or 1#' 로 만들어주면 된다. strrev함수로 인해 뒤집어서 입력해주면 된다.

반응형
반응형

Hand of plus

100

[문제 설명] 귀여운 아오바가 Beatcoin을 채굴하려고 한다. 아오바의 그래픽 카드를 도와주자.
[출제자] 정준영(Joon)

 

 

extract($_COOKIE); 을 사용하고 있다.

구글 확장프로그램을 이용해서 각각 4개의 이름과 값으로 쿠키를 추가해주면 된다.

 

 

 

The great escape

100

[문제 설명] 요원들은 배급받은 키를 쳐야 지령을 받을 수 있다고 한다. 요원들이 받는 지령을 몰래 받아보자.
[출제자] 정준영(Joon)

 

 

1부터 1000까지 브포를 해봤다. 틀렸다. 흠....

 

이것저것 해봤는데 디렉토리 인덱싱이 가능했다.

 

패스워드 찾아서 입력해주면 플래그가 나온다.

 

 

 

핵발사 시스템

300

[문제 설명] 귀여운 아오바가 어딘가로 핵을 쏘고싶어한다. 도와주자.
[출제자] 정준영(Joon)

 

 

1
2
3
4
5
6
7
8
9
10
11
12
<?php
    if(isset($_POST["Key1"]) && isset($_POST["Key2"]) && isset($_POST["Key3"])){
        if(hash('md5',$_POST["Key1"]) == hash('crc32',$_POST["Key2"])){
            if(hash('crc32',$_POST["Key2"]) == hash("md4"$_POST["Key3"])){
                if(hash("md5"$_POST["Key1"]) == hash("md4"$_POST["Key3"])){
                    echo "<script>alert('[Suzukaze aoba says]\\nThanks a lot! I launched an nuclear to some space!\\n\\nHere\'s a little prize!\\n[FLAG HERE]');</script>"
                }elseecho "3"; Fail(); }
            }elseecho "2"; Fail(); }
        }else{echo "1";  Fail(); }
    }
    function Fail(){ echo "<script>alert('[Suzukaze aoba]\\nT.T... I want to fire nuclear...');</script>"; }
?>
cs

 

매직해시문제 https://www.whitehatsec.com/blog/magic-hashes/

 

md5(Key1) == crc32(Key2) == md4(key3)

 

Key1 = 240610708

Key2 = 2332

Key3 = 48291204

 

반응형
반응형

리캡챠를 적용할 페이지는 login.php (.html이어도 적용 가능합니다.), 검증을 하는 페이지는 login_chk.php (php로 작성하였습니다.)로 가정을 하겠습니다.




1. 리캡챠 키를 생성


아래 링크에 접속합니다.

https://www.google.com/recaptcha/admin






Label 에는 그냥 이름 하나 적어줍니다. ex) login page


reCAPTCHA v3를 선택하고,


Domains에 사이트 도메인을 적어주고,


정책 동의에 체크한 후 register을 누릅니다.



Site key 와 Secret key는 기록해 둡니다.






2. 코드 삽입 (login.php)


login.php에서 <head></head> 태그 사이에 아래 코드를 삽입합니다.

<Site Key> 에 자신의 Site key를 입력합니다.


<script src='https://www.google.com/recaptcha/api.js?render=<Site key>'></script>


<script type="text/javascript">

  grecaptcha.ready(function() {

   grecaptcha.execute('<Site Key>', {action: 'loginpage'})

   .then(function(token) {

    document.getElementById('g-recaptcha-response').value = token;

   });

  });

</script>



login page 에서 로그인 <form> 태그안에 아래 코드를 삽입합니다.



    <form name="login_form" method="post" action="./login_chk.php">

...(중략)....

      <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">

    </form>






3. 코드 삽입 (login_chk.php)



php 코드 안에 아래 코드를 삽입합니다.

<Secret key> 안에 자신의 Secret key를 입력하면 됩니다.


//recaptcha

$captcha=$_POST['g-recaptcha-response'];

$secretKey = "<Secret key>";

$ip = $_SERVER['REMOTE_ADDR'];

$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);

$responseKeys = json_decode($response,true);


if($responseKeys["success"]) {

  //통과한 경우의 코드를 작성

 }

else {

  //통과하지 못한 경우의 코드를 작성

 }

//recaptcha


조건 if($responseKeys["success"]) 이 외에도 https://developers.google.com/recaptcha/docs/v3 문서의 Site Verify Response 부분을 참조하여 통과여부를 설정할 수 있습니다. 저는 간단히 success 부분만 받아 검증한 것입니다.



반응형
반응형

web











array로 날려주면 된다. input이 아닌 input[]으로 날리면 된다. 


아래 box들은 다 fake용도인것 같다.



http://chaneyoon.dothome.co.kr/array_string.php?input[]=you&input[]=want&input[]=flag?


FLAG{Th4nk_Y0U_H4CK!NG_C4MP!!}



반응형
반응형







https://mandu-mandu.tistory.com/204?category=723296 랑 같은문제다.





extract($_GET); 을 이용해서 $number와 $random_number 모두 내가 원하는 값으로 바꿔줄 수 있다.


http://chaneyoon.dothome.co.kr/randominteger.php?number=1&random_number=1




FLAG{th4nk_y0u_H4Ck!NGCAMP15th!}


반응형

+ Recent posts