11/15/2008

Apache+MySQL+PHP+OpenSSL in Ubuntu

SSL介紹 SSL(Secure Socket Layer)是Netscape所提出來的資料保密協定,採用了RC4、MD5,以及RSA等加密演算法。

網路上需要確定網站真的是那個網站,所以SSL也具備認證的機能。SSL是以金字塔的結構 組成,最下層的是一般的伺服器,它們經由向上跟CA申請取得SSL的憑證,CA會在SSL相關檔案上簽名,CA是具有公信力和認證能力的機構,CA必須向上跟RootCA(如政府機構等)申請。當使用者連結具SSL的服務時,伺服器會傳送憑證給使用者,使用端的程式接收到憑證後會向CA確認憑證,若CA確認這個憑是它們簽發的則會回傳給使用端正確的訊息。 具有SSL功能的網站可以向 世界少數幾個發證機構(例如目前最大的VeriSign或第二大的Thawte兩家認證公司)申請,經過嚴格的文件證明確認後,才能取得國際認可(較新版 的MSIE或Netscape瀏覽軟體會自動認得)的電子認證。

所有 SSL憑證都是發給公司或是法人,典型的 SSL 憑證將包括您的網域名稱(domain name)、您的公司名稱(company name)、您的住址(address)、您的所在城市(city)、您的省份(state)和您的國家(country),它也包含了憑證的到期日和負責核發此憑證的發證中心詳細資料。當一個瀏覽器連結到一個安全網站時,它將收到這個網站的SSL憑證並且檢驗它是否過期、它是否是已經被瀏覽器信任的發證中心所核發的,以及它是否如核發時 所登記的內容被該網站使用,假如有任何一項檢查不通過,瀏覽器將顯示一個警告訊息給使用者。

在Ubuntu上安裝 apache+mysql+php+openssl
sudo tasksel install lamp-server
安裝 lamp (apache mysql php)

sudo apt-get install mysql-admin mysql-gui-tools-common mysql-query-browser
安裝mysql的管理介面

sudo apt-get install -y php5-gd
安裝GD庫

sudo apt-get install -y openssl
安裝Openssl

sudo apt-get install -y ssl-cert
安裝簽署憑證的工具

sudo a2enmod ssl
安裝ssl模組

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl
sudo ln -s /etc/apache2/sites-available/ssl /etc/apache2/sites-enabled/ssl
複製一份預設擋供ssl用,並且用ln建立連結(捷徑)至sites-enabled/ssl

sudo vim /etc/apache2/sites-enabled/ssl
在以下位置後面加入紅色的設定值

NameVirtualHost *:443


sudo vim /etc/apache2/sites-enabled/default
在以下位置後面加入紅色的設定值

NameVirtualHost *:80
SSLEngine On
SSLCerficationFile /etc/apache2/etc/apache.pem


sudo vim /usr/sbin/make-ssl-cert
將"-keyout $output"改成"-keyout $output -days 3650"即可將憑證有效時間改成10年

sudo mkdir /etc/apache2/ssl
建立ssl憑證所擺放目錄

sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/etc/apache.pem
make-ssl-cert is a wrapper of OpenSSL
依照指示輸入憑證相關訊息,即可產生自簽的電子證書!

sudo /etc/init.d/apache2 force-reload
重新載入配置

sudo /etc/init.d/apache2 restart
重新啟動Apache2
產生自簽的CA 產生自簽的CA的意義是,自己架設一個CA,並為自己的伺服器的憑證簽名。則使用端收到憑證時,會向CA確定,這時就用自己架的CA去確認說憑證是有效的。當然這樣是沒有公信力的,而且把自己架的伺服器登記為CA需要手動加入,一般這樣做都是為了測試用。

參考以下連結
http://wiki.ubuntu.org.cn/OpenSSL 主要做兩件事情
第一件是架CA:Creating the Certificate Authority
第二件是架server:Creating a Self-Signed Server Certificate
並使用自己的CA為它簽名

11/09/2008

Reverse Engineering Tools

Microsoft Windows

Three tools pervade the warchest of the contemporary analyst on the Windows platform: IDA, SoftICE, and PE Tools. IDA is the Interactive Disassembler from Data Rescue. IDA is used to examine the executable on-disk. IDA provides useful features such as call graphs for analyzing program flow and automatic library detection.

SoftICE is a Ring 0 debugger from Compuware. Though SoftICE is no longer an offering from Compuware, it's use is still very common. While the author now uses WinDbg in place of SoftICE, some analysts have turned to OllyDbg. It is presumed that once Compuware decides to sell SoftICE, the debugger will regain it's previous popularity.

PE Tools is used to dump either a partial (region) or full in-memory image of an executable. It also includes the ability to automatically remove "Anti Dump Protection", and find the original OEP (AddressOfEntryPoint value of the IMAGE_OPTIONAL_HEADER structure). This tool would be used with a packed or encrypted executable. After the decompression or decryption occurs, PE Tools would be used to copy the image from memory for further analysis.

IDA is used to perform a static analysis on-disk, while a debugger is used to interrogate the executing program while in-memory. Based on the tools, this leads to the observation that a Protection Scheme must be functional in two environments - on-disk and in-memory. In the virus research community, challenging disassembly occurs in the anti-disassembly layer, while the implementation deterring dynamic analysis is known as a anti-debug layer.

Unix and Linux

For Unix and Linux, objdump (with it's PERL based wrapper dasm) and gdb are two available tools. gdb supports debugging of C, C++, Java, Fortran and Assembly among other languages. In addition, gdb is designed to work closely with the GNU Compiler Collection (GCC). objdump and dasm collectively act as full disassembler. Alternately, one can run Windows applications such as IDA on Linux using Wine, which acts as a compatibility layer for running Windows programs on Linux. Kris Kaspersky introduces additional tools and details procedures specific to the ELF file format in Hacker Disassembling Uncovered.

11/06/2008

人生第一筆薪水

就在今天
我拿到人生第一筆薪水了
真是莫名的感動

因為八九十月沒收入 債台高築
償還債務後也剩不下來
但我還是要好好記念今天 哈

11/03/2008

struct的特別用法

#include 

typedef struct A {
    int up : 1;
    int down : 1;
    int left : 1;
    int right : 1;
}Cell;

int main(void) {
    Cell c;

    c.up = c.down = c.left = c.right = 0;
    c.down = 1;
    printf("%d %d\n", sizeof(Cell), sizeof c);
    printf("%d %d %d %d\n", c.up & 1, c.down & 1, c.left & 1, c.right & 1);
    printf("%d %d %d %d\n", c.up, c.down, c.left, c.right);
    return 0;
}
結果:
4 4
0 1 0 0
0 -1 0 0

宣告的變數會變成bit-field struct因padding大小是4個byte.
裡面的變數都是bit 只能做bit operator 否則結果不是你想要的.