-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbconn_utf8.inc
365 lines (279 loc) · 9.66 KB
/
dbconn_utf8.inc
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<?php
@extract($_GET);
@extract($_POST);
@extract($_SESSION);
require_once "mysql-wrapper.php";
//$connect = mysql_pconnect ("localhost","unicity_db_user","unicity!2011");
//$connect = mysql_pconnect ("10.107.133.149","unicity_db_user","unicity!2011");
$connect = mysql_pconnect ("210.116.103.149","unicity_db_user","unicity!2011");
mysql_select_db("makelifebetter",$connect);
mysql_query("SET NAMES utf8");
mysql_query("SET character_set_server = utf8");
// mysql_set_charset('euckr',LINK);
// jkoh@inet.co.kr
function rtnSpecialCharCheck($str) {
if(preg_match("/[#\&\\+\-%@=\/\\\:;,\.\'\"\^`~\_|\!\/\?\*$#<>()\[\]\{\}]/i", $str, $match)) {
return false;
}
return true;
}
function protect_xss_v2($s){
$ret="";
if(is_array($s)){
$ret = $s;
}else{
$ret = trim($s);
if($ret!=""){
$ret = str_replace("<","<",$ret);
$ret = str_replace(">",">",$ret);
$ret = str_replace('"','"',$ret);
$ret = str_replace("'","'",$ret);
$ret = str_replace("(","(",$ret);
$ret = str_replace(")",")",$ret);
$ret = str_replace("-","-",$ret);
}
}
return $ret;
}
/**
* @brief iframe, script코드 제거
**/
function removeJSEvent($matches)
{
$tag = strtolower($matches[1]);
if(preg_match('/(src|href)=("|\'?)javascript:/i',$matches[2])) $matches[0] = preg_replace('/(src|href)=("|\'?)javascript:/i','$1=$2_javascript:', $matches[0]);
return preg_replace('/ on([a-z]+)=/i',' _on$1=',$matches[0]);
}
function removeSrcHack($matches)
{
$tag = strtolower(trim($matches[1]));
$buff = trim(preg_replace('/(\/>|>)/','/>',$matches[0]));
$buff = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $buff);
$oXmlParser = new XMLParser();
$xml_doc = $oXmlParser->parse($buff);
// src값에 module=admin이라는 값이 입력되어 있으면 이 값을 무효화 시킴
$src = $xml_doc->{$tag}->attrs->src;
$dynsrc = $xml_doc->{$tag}->attrs->dynsrc;
if(_isHackedSrc($src) || _isHackedSrc($dynsrc) ) return sprintf("<%s>",$tag);
return $matches[0];
}
function _isHackedSrc($src) {
if(!$src) return false;
if($src && preg_match('/javascript:/i',$src)) return true;
if($src)
{
$url_info = parse_url($src);
$query = $url_info['query'];
$queries = explode('&', $query);
$cnt = count($queries);
for($i=0;$i<$cnt;$i++)
{
$pos = strpos($queries[$i],'=');
if($pos === false) continue;
$key = strtolower(trim(substr($queries[$i], 0, $pos)));
$val = strtolower(trim(substr($queries[$i] ,$pos+1)));
if(($key == 'module' && $val == 'admin') || $key == 'act' && preg_match('/admin/i',$val)) return true;
}
}
return false;
}
// sql injection 처리
function quote_smart($value) {
/* sql injection 처리 */
$banlist = array(
"insert", "select", "update", "delete", "distinct", "having", "truncate", "replace",
"handler", "like", " as ", "or ", "procedure", "limit", "order by", "group by", "asc", "desc"
);
$value = trim(str_replace($banlist, '', strtolower($value)));
/* //sql injection 처리 */
//$value = addslashes($value);
/* XSS 처리 */
// iframe 제거
$value = preg_replace("!<iframe(.*?)<\/iframe>!is", '', $value);
// script code 제거
$value = preg_replace("!<script(.*?)<\/script>!is", '', $value);
// meta 태그 제거
$value = preg_replace("!<meta(.*?)>!is", '', $value);
// style 태그 제거
$value = preg_replace("!<style(.*?)<\/style>!is", '', $value);
// XSS 사용을 위한 이벤트 제거
$value = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeJSEvent, $value);
/**
* 이미지나 동영상등의 태그에서 src에 관리자 세션을 악용하는 코드를 제거
* - 취약점 제보 : 김상원님
**/
//$value = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeSrcHack, $value);
/* //XSS 처리 */
// stripslashes
if (get_magic_quotes_gpc()) {
$value = htmlspecialchars(stripslashes($value));
}else{
$value = htmlspecialchars($value);
}
// if(!is_numeric($value)) {
// $value = "'" . mysql_real_escape_string($value) . "'";
// }
$value = htmlentities($value, ENT_QUOTES, 'UTF-8');
$value = str_replace("\"",""", $value);
$value = str_replace("'","'", $value);
//$value = str_replace("%","%", $value);
$value = str_replace(">",">", $value);
$value = str_replace("<","<", $value);
return $value;
}
// sql injection 처리
function upper_quote_smart($value) {
/* sql injection 처리 */
$banlist = array(
"INSERT", "SELECT", "UPDATE", "DELETE", "DISTINCT", "HAVING", "TRUNCATE", "REPLACE",
"HANDLER", "LIKE", " AS ", "OR ", "PROCEDURE", "LIMIT", "ORDER BY", "GROUP BY", "ASC", "DESC"
);
$value = trim(str_replace($banlist, '', strtoupper($value)));
/* //sql injection 처리 */
//$value = addslashes($value);
/* XSS 처리 */
// iframe 제거
$value = preg_replace("!<iframe(.*?)<\/iframe>!is", '', $value);
// script code 제거
$value = preg_replace("!<script(.*?)<\/script>!is", '', $value);
// meta 태그 제거
$value = preg_replace("!<meta(.*?)>!is", '', $value);
// style 태그 제거
$value = preg_replace("!<style(.*?)<\/style>!is", '', $value);
// XSS 사용을 위한 이벤트 제거
$value = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeJSEvent, $value);
/**
* 이미지나 동영상등의 태그에서 src에 관리자 세션을 악용하는 코드를 제거
* - 취약점 제보 : 김상원님
**/
//$value = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeSrcHack, $value);
/* //XSS 처리 */
// stripslashes
if (get_magic_quotes_gpc()) {
$value = htmlspecialchars(stripslashes($value));
}else{
$value = htmlspecialchars($value);
}
// if(!is_numeric($value)) {
// $value = "'" . mysql_real_escape_string($value) . "'";
// }
$value = htmlentities($value, ENT_QUOTES, 'UTF-8');
$value = str_replace("\"",""", $value);
$value = str_replace("'","'", $value);
//$value = str_replace("%","%", $value);
$value = str_replace(">",">", $value);
$value = str_replace("<","<", $value);
return $value;
}
function str_quote_smart($value) {
/* sql injection 처리 */
$banlist = array(
"insert", "select", "update", "delete", "distinct", "having", "truncate", "replace",
"handler", "like", " as ", "or ", "procedure", "limit", "order by", "group by", "asc", "desc", "iframe", "script", "meta", "style"
);
//$value = addslashes($value);
$value = trim(str_ireplace($banlist, '', $value));
/* //sql injection 처리 */
/* XSS 처리 */
// iframe 제거
$value = preg_replace("!<iframe(.*?)<\/iframe>!is", '', $value);
// script code 제거
$value = preg_replace("!<script(.*?)<\/script>!is", '', $value);
// meta 태그 제거
$value = preg_replace("!<meta(.*?)>!is", '', $value);
// style 태그 제거
$value = preg_replace("!<style(.*?)<\/style>!is", '', $value);
// XSS 사용을 위한 이벤트 제거
$value = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeJSEvent, $value);
/**
* 이미지나 동영상등의 태그에서 src에 관리자 세션을 악용하는 코드를 제거
* - 취약점 제보 : 김상원님
**/
//$value = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeSrcHack, $value);
/* //XSS 처리 */
// stripslashes
if (get_magic_quotes_gpc()) {
$value = htmlspecialchars(stripslashes($value));
}else{
$value = htmlspecialchars($value);
}
//$value = htmlentities($value, ENT_QUOTES, 'UTF-8');
$value = str_replace("\"",""", $value);
$value = str_replace("'","'", $value);
$value = str_replace("%","%", $value);
$value = str_replace(">",">", $value);
$value = str_replace("<","<", $value);
// if(!is_numeric($value)) {
// $value = "'" . mysql_real_escape_string($value) . "'";
// }
return $value;
}
function html_quote_smart($value) {
/* sql injection 처리 */
$banlist = array(
"insert", "select", "update", "delete", "distinct", "having", "truncate", "replace",
"handler", "like", " as ", "or ", "procedure", "limit", "order by", "group by", "asc", "desc", "iframe", "script", "meta", "style",
"INSERT", "SELECT", "UPDATE", "DELETE", "DISTINCT", "HAVING", "TRUNCATE", "REPLACE",
"HANDLER", "LIKE", " AS ", "OR ", "PROCEDURE", "LIMIT", "ORDER BY", "GROUP BY", "ASC", "DESC", "IFRAME", "SCRIPT", "META", "STYLE"
);
//$value = addslashes($value);
$value = trim(str_ireplace($banlist, '', $value));
/* //sql injection 처리 */
/* XSS 처리 */
// iframe 제거
$value = preg_replace("!<iframe(.*?)<\/iframe>!is", '', $value);
// script code 제거
$value = preg_replace("!<script(.*?)<\/script>!is", '', $value);
// meta 태그 제거
$value = preg_replace("!<meta(.*?)>!is", '', $value);
// style 태그 제거
$value = preg_replace("!<style(.*?)<\/style>!is", '', $value);
// XSS 사용을 위한 이벤트 제거
$value = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeJSEvent, $value);
/**
* 이미지나 동영상등의 태그에서 src에 관리자 세션을 악용하는 코드를 제거
* - 취약점 제보 : 김상원님
**/
//$value = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeSrcHack, $value);
/* //XSS 처리 */
// stripslashes
//if (get_magic_quotes_gpc()) {
// $value = htmlspecialchars(stripslashes($value));
//}else{
// $value = htmlspecialchars($value);
//}
//$value = htmlentities($value, ENT_QUOTES, 'UTF-8');
$value = str_replace("\"",""", $value);
$value = str_replace("'","'", $value);
$value = str_replace("%","%", $value);
// $value = str_replace(">",">", $value);
// $value = str_replace("<","<", $value);
// if(!is_numeric($value)) {
// $value = "'" . mysql_real_escape_string($value) . "'";
// }
return $value;
}
function chkDate($str, $format) {
if ($format == "YYYY-MM-DD") {
//$yyyy = date("Y",strtotime($str));
//$mm = date("m",strtotime($str));
//$dd = date("d",strtotime($str));
$yyyy = left($str, 4);
$mm = substr($str, 5,2);
$dd = right($str,2);
if ((!is_numeric($yyyy)) || (!is_numeric($mm)) || (!is_numeric($dd)) ) {
return false;
} else {
return checkdate($mm , $dd, $yyyy);
}
/*
echo $yyyy."<br>";
echo $mm."<br>";
echo $dd."<br>";
*/
//return true;
} else {
return false;
}
}
?>