* 태크안의 내용만 추출

$string = "<div class=\"name\">anyting</div>1234<div class=\"name\">anyting</div >abcd";  
echo preg_replace('/(<div[^>]*>)(.*?)(<\/div.*?>)/i', '$2', $string);
* 태그제거
$string = "<table class=\"name\"><tr><td>anyting1</td></tr></table><table class=\"name\"><tr><td>anyting2</td><td>anyting3</td></tr></table>";
echo preg_replace('/\<[\/]?(table|tr|td)([^\>]*)\>/i', '', $string);​
출처 : http://roresy.tistory.com/2311

 

블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,

remove_xss 함수

php, codeigniter 2015. 5. 12. 14:30
<?php
function RemoveXSS($val) {
	// remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
	// this prevents some character re-spacing such as <java\0script>
	// note that you have to handle splits with \n, \r, and \t later since they *are*
	// allowed in some inputs
	$val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '', $val);

	// straight replacements, the user should never need these since they're normal characters
	// this prevents like <IMG SRC=&#X40&#X61&#X76&#X61&#X73&#X63&#X72&#X69&#X70&#X74&
	// #X3A&#X61&#X6C&#X65&#X72&#X74&#X28&#X27&#X58&#X53&#X53&#X27&#X29>
	$search = 'abcdefghijklmnopqrstuvwxyz';
	$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
	$search .= '1234567890!@#$%^&*()'; 
	$search .= '~`";:?+/={}[]-_|\'\\'; 
	for ($i = 0; $i < strlen($search); $i++) { 
    	// ;? matches the ;, which is optional
    	// 0{0,7} matches any padded zeros, which are optional and go up to 8 chars

    	// &#x0040 @ search for the hex values
    	$val = preg_replace('/(&#[x|X]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val);
    	// with a ;

    	// &#00064 @ 0{0,7} matches '0' zero to seven times
    	$val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
  	}

  	// now the only remaining whitespace attacks are \t, \n, and \r
  	$ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
  	$ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
  	$ra = array_merge($ra1, $ra2);
    
  	$found = true; // keep replacing as long as the previous round replaced something 
  	while ($found == true) {
    	$val_before = $val;
    	for ($i = 0; $i < sizeof($ra); $i++) {
      		$pattern = '/';
      		for ($j = 0; $j < strlen($ra[$i]); $j++) {
        		if ($j > 0) {
          			$pattern .= '(';
          			$pattern .= '(&#[x|X]0{0,8}([9][a][b]);?)?';
          			$pattern .= '|(&#0{0,8}([9][10][13]);?)?';
          			$pattern .= ')?';
        		}
        		$pattern .= $ra[$i][$j];
      		}
      		$pattern .= '/i'; 
      		$replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2); // add in <> to nerf the tag
      		$val = preg_replace($pattern, $replacement, $val); // filter out the hex tags
      		if ($val_before == $val) {
				// no replacements were made, so exit the loop
				$found = false;
			}
		}
	}
	return $val;
}
?>
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,

1. SSO 솔류션을 이용하여 스크립트 체크을통해 로그인을 사용할수 있다. 

- SSO 솔류션에서 정보를 가져오면 가능하다.

 

2. 하나의 웹언어에서 쿠키를 생성하여 다른 웹언어에서 읽어들여 세션변수에 저장합니다.

- 대신 같은 1차,2차 도메인에서만 쿠키변수에 쓰기,읽기가 가능하다.

 

www를 붙은 도메인과 붙지 않은 도메인에서 제대로 세션공유가 안일어날때

 

* index.php

<?
session_start();
$_SESSION["name"]="이xx";
$_SESSION["name1"]="하하하";
?>
<a href="http://www.skin4u.net/test1.php">www.skin4u.net</a>
<a href="http://skin4u.net/test2.php">skin4u.net</a>

* test1.php

<?
session_start();
echo $_SESSION["name"];
echo $_SESSION["name1"];
?>

* test2.php

<?
session_start();
echo $_SESSION["name"];
echo $_SESSION["name1"];
?>

 

www.skin4u.net에서 서핑을 하다가 세션을 구울시 skin4u.net로 다시 이동하여 서핑할경우 세션이 안먹혀 에러가 나는 경우가 있다 그럴경우에는 아래와 같이 조치한다.

 

session_start(); 전에 아래 코드를 넣어준다.

@header('P3P: CP="NOI CURa ADMa DEVa TAIa OUR DELa BUS IND PHY ONL UNI COM NAV INT DEM PRE"');
ini_set("session.cookie_domain", ".webprogram.co.kr");
출처 : http://www.zetswing.com/bbs/board.php?bo_table=PHP_LEC&wr_id=6&page=3
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,
<?
/*
-i = input file
-deinterlace = deinterlace pictures
-an = disable audio recording
-ss = start time in the video (seconds)
-t = duration of the recording (seconds)
-r = set frame rate
-y = overwrite existing file
-s = resolution size
-f = force format
*/

// where ffmpeg is located  
$ffmpeg = $_SERVER['DOCUMENT_ROOT'].'/ffmpeg.exe';
//video dir  
$video = $_SERVER['DOCUMENT_ROOT']."/test_media/207.mp4";
//where to save the image  
$image = $_SERVER['DOCUMENT_ROOT']."/test_media/207.jpg";
//time to take screenshot at  
$interval = 100;
//screenshot size  
$size = '640x480';  
//ffmpeg command  
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $image 2>&1";

`$cmd`;
?>
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,
CREATE TABLE dbo.ci_sessions (
	session_id varchar(40) DEFAULT '0' NOT NULL,
	ip_address varchar(16) DEFAULT '0' NOT NULL,
	user_agent varchar(120) NOT NULL,
	last_activity int DEFAULT 0 NOT NULL,
	user_data varchar(max) NOT NULL, -- use varchar(max) instead of MySQL TEXT data type
	PRIMARY KEY (session_id)
)
GO

-- Simalate MySQL 'UNSIGNED' field option
ALTER TABLE dbo.ci_sessions ADD CONSTRAINT last_activity_unsigned
	CHECK (last_activity >= 0)
GO

CREATE INDEX last_activity_idx
ON dbo.ci_sessions (last_activity)
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,
/application/core/MY_Router.php

MY_Router.php
다운로드

/system/database/drivers/mssql/mssql_driver.php

mssql_driver.php
다운로드

 

블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,