2010年7月7日 星期三

PHP Obfuscator

若是不想要PHP的原始碼讓別人看到, 可以使用open source的PHP Screw, 以下是1.5的安裝步驟:

0.系統需求
PHP 5.x的環境
具有zlib的支援(可透過<?php gzopen(); ?>來檢查)

1.解壓縮
修改my_screw.h, 裡面的數字就是seed, 可視為密碼

2.編譯成so
$ phpize
$ ./configure –with-php-config=/path/to/php-config
$ make

若發生錯誤如
/path/to/php_screw-1.5/php_screw.c:78: error: too few arguments to function 'org_compile_file'
/path/to/php_screw-1.5/php_screw.c:84: error: too few arguments to function 'org_compile_file'
/path/to/php_screw-1.5/php_screw.c:91: error: too few arguments to function 'org_compile_file'
/path/to/php_screw-1.5/php_screw.c:93: error: too few arguments to function 'org_compile_file'
從官方bug列表找到解決方法:
modify php_screw.c
org_compile_file(file_handle, type);
to
org_compile_file(file_handle, type TSRMLS_CC);

或發生錯誤如
/path/to/php_screw-1.5/php_screw.c: In function 'zm_startup_php_screw':
/path/to/php_screw-1.5/php_screw.c:124: error: 'zend_compiler_globals' has no member named 'extended_info'
/path/to/php_screw-1.5/php_screw.c: In function 'zm_shutdown_php_screw':
/path/to/php_screw-1.5/php_screw.c:133: error: 'zend_compiler_globals' has no member named 'extended_info'
閱讀source後
modify php_screw.c
CG(extended_info) = 1;
to
// CG(extended_info) = 1;

3.修改php.ini設定
[php_screw]
extension=php_screw.so

4.編譯混淆器
$ cd tools $ make )

5.使用(對foo.php做混淆)
$ ./tools/screw foo.php
$ Success Crypting(foo.php)

若要對多個檔案進行混淆,可以簡單的使用兩行指令搞定
$ find . -name "*.php" -exec /path/to/tools/screw -exec {} \;
$ find . -name "*.screw" -exec rm -f {} ;

注意, 混淆過的檔案, 對方主機需安裝php_screw才能讀取, 所以虛擬主機類的應該就沒辦法用這一招了...

參考資料:
* 使用自由加密軟件PHP screw對PHP源碼加密
* 用php_screw加密PHP代碼

2010年4月24日 星期六

Amazon S3

之前有用Amazone S3存點資料, 現在不想用了, 就順手紀錄相關連結吧...
PHP: Amazon S3 PHP class
ASP.Net: ThreeSharp
Command: s3cmd
Firefox: S3Fox

[轉貼] 【討論】如何在PHP下使用DES加密解密算法?

原文標題: 【討論】如何在PHP下使用DES加密解密算法?
原文作者: suiphone
發表日期: 2004-12-29 15:15
原始連結: https://bbs.et8.net/bbs/showthread.php?t=616987

之前看到的, 紀錄一下, 程式部份為全部引用(稍微排版了一下)...

$key = $_REQUEST['key'];
 
//Encrypt Function (編碼)
function encrypt($encrypt) {
  global $key;
  $iv = mcrypt_create_iv(mcrypt_get_iv_size(
        MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
  $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, 
                              $encrypt, MCRYPT_MODE_ECB, $iv);
  $encode = base64_encode($passcrypt);
  return $encode;
}
 
//Decrypt Function (解碼)
function decrypt($decrypt) {
  global $key;
  $decoded = base64_decode($decrypt);
  $iv = mcrypt_create_iv(mcrypt_get_iv_size(
        MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
  $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, 
                              $decoded, MCRYPT_MODE_ECB, $iv);
  return $decrypted;
}  

2010年3月10日 星期三

[轉錄] SSH Tunnel

最近有透過SSH Tunnel瀏覽網頁的需求, 剛好看到這篇, 寫的簡單易懂就備份起來了... 感謝A0933305


update (2010-07-02)

若是在*nix上, 則使用先和ssh server建立ssh tunnel後,將所有從指定port出去的封包都導到ssh server
語法:
$ ssh -D LOCAL_PORT SSH_SERVER_IP
例:
$ ssh -D 8888 192.168.1.1
使用:
所有從本機3128 port出去的連線都會被導到192.168.1.1,此時在firefox中設定socks主機為127.0.0.1 8888 port,就可以用firefox透過192.168.1.1連到外部網路

參考資料:
[筆記]被防火牆擋住出不去? ssh tunnel讓你鑽洞溜出去

2010年3月9日 星期二

[轉貼][轉貼] 上傳檔案前, JavaScript檢查檔案格式, 大小

原文標題: [SCript] [轉貼]上傳檔案前,JavaScript檢查檔案格式、大小
原文作者: topcat
發表日期: 2009-02-20 14:14
原始連結: http://itgroup.blueshop.com.tw/topcat/aspx?n=convew&i=5684

之前看到的, 紀錄一下, 程式部份為全部引用(稍微排版了一下)...
在檔案送出前以JavaScript檢查檔案格式與大小在不同瀏覽器上有稍微的不同, 目前測的結果是IE6/IE7可以... 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=big5"> 
<title>上傳</title> 
</head> 
<body> 
<form ACTION="upload.asp" METHOD="POST" name="FileForm" enctype="multipart/form-data"> 
圖片: <input type="file" name="file1" size="20" id="file1"> 
<input type="button" value="確定上傳" onClick="checkFile()"> 
</form> 
</body> 
</html> 
<script language="JavaScript"> 

//這裡控制要檢查的項目,true表示要檢查,false表示不檢查 
var isCheckImageType = true;   //是否檢查圖片副檔名 
var isCheckImageWidth = true;  //是否檢查圖片寬度 
var isCheckImageHeight = true; //是否檢查圖片高度 
var isCheckImageSize = true;   //是否檢查圖片檔案大小 

var ImageSizeLimit = 100000;   //上傳上限,單位:byte 
var ImageWidthLimit = 1200;    //圖片寬度上限 
var ImageHeightLimit = 1000;   //圖片高度上限 

function checkFile() { 
 var f = document.FileForm; 
 var re = /\.(jpg|gif)$/i;  //允許的圖片副檔名 
 if (isCheckImageType && !re.test(f.file1.value)) { 
   alert("只允許上傳JPG或GIF影像檔"); 
 } else { 
   var img = new Image(); 
   img.onload = checkImage; 
   img.src = f.file1.value; 
 } 
} 
function checkImage() { 
 if (isCheckImageWidth && this.width > ImageWidthLimit) { 
   showMessage('寬度','px',this.width,ImageWidthLimit); 
 } else if(isCheckImageHeight && this.height > ImageHeightLimit) { 
   showMessage('高度','px',this.height,ImageHeightLimit); 
 } else if (isCheckImageSize && this.fileSize > ImageSizeLimit) { 
   showMessage('檔案大小','kb',this.fileSize/1000,ImageSizeLimit/1000);   
 } else { 
   document.FileForm.submit(); 
 } 
} 
function showMessage(kind,unit,real,limit) { 
 var msg = "您所選擇的圖片kind為 real unit\n超過了上傳上限 limit unit\n不允許上傳!" 
 alert(msg.replace(/kind/,kind).replace(/unit/g,unit).replace(/real/,real).replace(/limit/,limit)); 
} 
</script>

[Embedded] The GNU configure and build system - Cross Compilation Tools

在做cross compilation的時候, 需要將手邊的程式編譯成可在目標裝置上執行的代碼, 這時候就會需要用到cross compiler中的系統參數了...

根據GCC documentation可以知道
--build: the machine you are building on
--host: the machine you are building for
--target: the machine that GCC will produce code for

翻譯一下就是build就是你現在使用的機器,host就是你編譯好的程序能夠運行的平台,target是編譯程序能夠處理的平台,一般使用在開發工具上

因此如果我們希望在x86環境下編譯一個可以在arm環境中處理mips的gcc,可能會類似 ./configure --build=i386-linux --host=arm-linux --target=mipsel-linux

reference:
* GCC documentation
* GNU Configure中的 build target和host的區別