• 09Jul

    ผมเขียนบันทึกนี้ หลังจาก server ผมมีคนพยายามเข้ามา hack จนเครื่องผมค้างไปเลย เป็นสิ่งที่ดีคับ ทำให้ผมมีความรู้ และเข้าใจมากขึ้น ผมหาอ่านบทความ และก็ได้แปลมา ขอนอกเรื่องครับ ผมเขียน blog ที่อุณหภูมิ 31 องศาเซลเซียส อ้าวได้ใจมากคับ

    หลังจากติดตั้ง LAMP แล้ว สิ่งที่อย่างแรกคือ การป้องกันการโจมตี
    Step 1: ป้องกันการแสดงผลแบบ list view

    sudo nano /etc/apache2/sites-available/default

    เพิ่มเครื่องหมายลบ – หน้า Index ตามแบบข้างล่าง

    <Directory /var/www/>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>

     

    Step 2 :

    สำหรับ Apache ตั้งแต่ version 1.3.34 และ 2.0.55 ขึ้นไปนะครับ ทำได้โดยเพิ่ม

    TraceEnable Off

    ใน config ของ apache ซึ่งจะทำให้ปิดการใช้งาน Trace ได้

    ถ้าเป็นรุ่นเก่ากว่านี้หน่อยต้องเปิดใช้ rewrite module ของ Apache.

    sudo a2enmod rewrite

    เพื่อหลีกเลี่ยงการโจมตีแบบ Cross-Site-Tracing ให้เพิ่ม 3 บรรทัดนี้ ใน ” <VirtualHost *:80>” :

        RewriteEngine On
        RewriteCond %{REQUEST_METHOD} ^(TRACETRACK)
        RewriteRule .* – [F]

    Step 3 :

    เพื่อป้องการทำ HTTP DoS, DDoS หรือ Brute Force attack, ต้องติดตั้ง Moduleนี้

    sudo apt-get install libapache2-mod-evasive

    Step 4 :

    To screen out bad URL requests, such as /etc/shadow or MySQL injection and etc. You should install mod_security module. If you installed a amd64 (64-bit) version of Ubuntu Server, please replaced i386 with amd64 for the following commands.

    wget http://etc.inittab.org/~agi/debian/libapache-mod-security2/libapache-mod-security_2.5.9-1_i386.deb

    wget http://etc.inittab.org/~agi/debian/libapache-mod-security2/mod-security-common_2.5.9-1_all.deb

    sudo dpkg -i libapache-mod-security_2.5.9-1_i386.deb mod-security-common_2.5.9-1_all.deb

    Step 5 :

    ไม่อนุญาตให้ print the error pages

    sudo nano /etc/apache2/conf.d/security

    แก้ไขตามนี้

    ServerToken Prod
    ServerSignature Off

    Step 6 :

    มาถึงคิวของ PHP

    sudo nano /etc/php5/apache2/php.ini

    แก้ไขให้เป็นแบบข้างล่างนี้

    display_errors = Off
    log_errors = On
    allow_url_fopen = Off
    expose_php = Off
    enable_dl = Off
    disable_functions = system, show_source, symlink, exec, dl, shell_exec, passthru, phpinfo, escapeshellarg, escapeshellcmd

    Step 7 :

    ขั้นตอนสุดท้าย

    sudo /etc/init.d/apache2 restart

    Step 8 :

    sudo nano /etc/sysctl.conf

    เอา # ออก

    #Enable TCP SYN Cookie Protection
    net.ipv4.tcp_syncookies = 1

    สั่งให้ทำงานเลย

    sudo /sbin/sysctl -p

    ผมเขียนบันทึกนี้ หลังจาก server ผมมีคนพยายามเข้ามา hack จนเครื่องผมค้างไปเลย เป็นสิ่งที่ดีคับ ทำให้ผมมีความรู้ และเข้าใจมากขึ้น ผมหาอ่านบทความ และก็ได้แปลมา ขอนอกเรื่องครับ ผมเขียน blog ที่อุณหภูมิ 31 องศาเซลเซียส อ้าวได้ใจมากคับ

    หลังจากติดตั้ง LAMP แล้ว สิ่งที่อย่างแรกคือ การป้องกันการโจมตี
    Step 1: ป้องกันการแสดงผลแบบ list view

    sudo nano /etc/apache2/sites-available/default

    เพิ่มเครื่องหมายลบ – หน้า Index ตามแบบข้างล่าง

    <Directory /var/www/>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>

     

    Step 2 :

    สำหรับ Apache ตั้งแต่ version 1.3.34 และ 2.0.55 ขึ้นไปนะครับ ทำได้โดยเพิ่ม

    TraceEnable Off

    ใน config ของ apache ซึ่งจะทำให้ปิดการใช้งาน Trace ได้

    ถ้าเป็นรุ่นเก่ากว่านี้หน่อยต้องเปิดใช้ rewrite module ของ Apache.

    sudo a2enmod rewrite

    เพื่อหลีกเลี่ยงการโจมตีแบบ Cross-Site-Tracing ให้เพิ่ม 3 บรรทัดนี้ ใน ” <VirtualHost *:80>” :

        RewriteEngine On
        RewriteCond %{REQUEST_METHOD} ^(TRACETRACK)
        RewriteRule .* – [F]

    Step 3 :

    เพื่อป้องการทำ HTTP DoS, DDoS หรือ Brute Force attack, ต้องติดตั้ง Moduleนี้

    sudo apt-get install libapache2-mod-evasive

    Step 4 :

    To screen out bad URL requests, such as /etc/shadow or MySQL injection and etc. You should install mod_security module. If you installed a amd64 (64-bit) version of Ubuntu Server, please replaced i386 with amd64 for the following commands.

    wget http://etc.inittab.org/~agi/debian/libapache-mod-security2/libapache-mod-security_2.5.9-1_i386.deb

    wget http://etc.inittab.org/~agi/debian/libapache-mod-security2/mod-security-common_2.5.9-1_all.deb

    sudo dpkg -i libapache-mod-security_2.5.9-1_i386.deb mod-security-common_2.5.9-1_all.deb

    Step 5 :

    ไม่อนุญาตให้ print the error pages

    sudo nano /etc/apache2/conf.d/security

    แก้ไขตามนี้

    ServerToken Prod
    ServerSignature Off

    Step 6 :

    มาถึงคิวของ PHP

    sudo nano /etc/php5/apache2/php.ini

    แก้ไขให้เป็นแบบข้างล่างนี้

    display_errors = Off
    log_errors = On
    allow_url_fopen = Off
    expose_php = Off
    enable_dl = Off
    disable_functions = system, show_source, symlink, exec, dl, shell_exec, passthru, phpinfo, escapeshellarg, escapeshellcmd

    Step 7 :

    ขั้นตอนสุดท้าย

    sudo /etc/init.d/apache2 restart

    Step 8 :

    sudo nano /etc/sysctl.conf

    เอา # ออก

    #Enable TCP SYN Cookie Protection
    net.ipv4.tcp_syncookies = 1

    สั่งให้ทำงานเลย

    sudo /sbin/sysctl -p

     

    ที่มา:

  • 09Jul

    http://www.sourceguardian.com/protect_php_scripts.html
    http://www.zend.com/en/products/guard/

  • 10Sep

    ที่มา: http://www.thaihosttalk.com/index.php?topic=7155.0

  • 25Aug
    You can do this with the ffmpeg-php extension.

    $file = ‘/path/to/your/movie.flv’;
    $movie = new ffmpeg_movie($file);
    $height = $movie->getFrameHeight();
    $width = $movie->getFrameWidth();
    $size = filesize($file);

    Source(s):

    http://ffmpeg-php.sourceforge.net/
    http://ffmpeg-php.sourceforge.net/doc/api/ffmpeg_movie.php
  • 04May

    ตัวแปร cookie จะเป็นตัวแปรพิเศษ ที่จะเก็บข้อมูลฝั่ง Client โดยสามารถใช้ได้ทุกหน้า webpage
    ซึ่งจะต้องมีการกำหนดอายุของตัวแปร cookie ด้วย

    วิธีใช้ cookie จะต้องเขียน

    setcookie('cookie_name', 'cookie_value', 'cookies_time', 'cookie_path', 'domain');

    โดย
    cookie_name เป็นชื่อตัวแปร cookie
    cookie_value เป็นค่าของตัวแปร cookie
    cookie_time เป็นการกำหนดเวลาหมดอายุของตัวแปร cookie หน่วยเป็น วินาที
    เช่น time()+86400 -> cookie นี้จะหมดอายุอีก 86400 วินาทีข้างหน้า

    ส่วนของ cookie_path และ domain เราจะไม่ใส่ก็ได้
    ซึ่งถ้าเราไม่ใส่ domain ก็จะเป็น domain นั้น ๆ(host นั้นๆ) ที่เราประกาศตัวแปร
    แต่ถ้าเราต้องการให้ cookie ของเรานั้นสามารถใช้ได้ทุก subdomain ของ web เรา
    เราต้องเขียนในส่วนของ domain ว่า ‘.domain.com’ (ต้องใส่จุดด้วยนะ สำคัญ!! )

    แต่ถ้าเ้ราต้องการลบ cookie ให้เราใส่ชื่อ cookie ที่เราต้องการจะลบ และใส่ในส่วนของ cookie_value เป็นค่าว่าง

    setcookie('cookie_name', '');
  • 18Apr
    เป็นคำสั่งแปลงวิดีโอให้เป็นไฟล์ flv ผมแปลงกลับไปกลับมาเป็นหลายๆ format เพราะต้องการจะทดสอบว่าบน server มันสามารถแปลงเป็น flv โดยใช้ไฟล์อะไรได้บ้าง ลองแค่นี้คงพออิๆ…. Continue reading »
  • 17Dec

    การกำหนดค่า Session Timeout กรณีไม่แก้ไข php.ini

    $garbage_timeout = 3600; // 3600 seconds = 60 minutes = 1 hour
    ini_set(’session.gc_maxlifetime’, $garbage_timeout);
    // การประกาศ ini_set จะต้องประกาศก่อนที่จะ open session
    session_start() ;

    อีกตัวอย่าง

    /* set the cache expire to 30 minutes */
    session_cache_expire(30);
    $cache_expire session_cache_expire();

    /* start the session */
    session_start();

    กรณีกำหนด cookie timeout

    $cookie_path = “/”;
    $cookie_timeout = 60 * 30; // in seconds
    session_set_cookie_params($cookie_timeout, $cookie_path);

  • 11Dec

    สำหรับ code ที่นำเสนอนี้ มีความน่าสนใจตรงที่จะทำการตรวจสอบหาเมล์เซิร์ฟเวอร์ให้ด้วย
    ดังนั้นอีเมล์ที่จะทำการตรวจสอบ จะต้องมีเมล์เซิร์ฟเวอร์นั้นจริงๆ จึงจะผ่าน .. แม้จะใส่อีเมล์ปลอม ก็ต้องมีโดเมนนั้นจริงๆ Continue reading »

  • 02Oct

    Continue reading »