วันศุกร์ที่ 19 สิงหาคม พ.ศ. 2554

การ Export Policy CheckPoint Firewall


ใช้ Command
cp_merge export_policy
จะได้มาเป็น File .pol
ทำให้ดูง่ายด้วยการแปลงเป็น html โดยใช้ perl script
โปรแกรมค่อนข้างจะงงเพราะเขียนเอง มั่วไปเรื่อย
#!c:\perl\bin\perl
#print "Content-type:text/html\n\n";
#use DBI;
#$db="access";
#$host="localhost";
# $userdb="root";
# $passwd="helloyot";
#$connectionInfo="DBI:mysqlPP:$db;$host";
#use Switch 'Perl5';
sub ReadDIR(){
 my $dir = 'D:\1105';
 opendir DIR, $dir or die "read dir $dir - $!";
 my @FILEREAD = grep /^praudit/, readdir DIR;
#my @FILEREAD = grep /'TAF'/. readdir DIR;
 closedir DIR;
 open(IndexFile,"ReadFileLog.soc");
 @INDEX=<indexfile>;</indexfile>
 $index=join(/\|/,@INDEX);
 close(IndexFile);
 for($ii=0;$ii
  if($index !~/$FILEREAD[$ii]/){
   open(IndexFile,">>ReadFileLog.soc");
   #print IndexFile "$FILEREAD[$ii]\n";
   close(IndexFile);
   #print"$FILEREAD[$ii]\n";
   &ReadFile($FILEREAD[$ii]);
  }
 }
}
sub str_replace {
 my $replace_this = shift;
 my $with_this  = shift;
 my $string   = shift;

 my $length = length($string);
 my $target = length($replace_this);

 for(my $i=0; $i
  if(substr($string,$i,$target) eq $replace_this) {
   $string = substr($string,0,$i) . $with_this . substr($string,$i+$target);
   return $string; #Comment this if you what a global replace
  }
 }
 return $string;
}
sub ReadFile($){
#print $filetoread."\n";
 #my $dir = 'd:\CAT Data';
 #($filetoread)=@_;
 #print"--------------$filetoread-------------\n";
 #$rfile=$dir.'\\'.$filetoread;
 #print $rfile;
 #$dbh = DBI->connect($connectionInfo,$userdb,$passwd);
 #open(FILE,"$rfile");
 #open(FILE,"praudit-18Jun10");
 my $dir = 'D:\Log\TBank\log';
 ($filetoread)=@_;
 #print"--------------$filetoread-------------\n";
 $rfile=$dir.'\\'.$filetoread;
 #print $rfile."\n";
 $newfile="new-".$filetoread;
 #print $newfile."\n";
 #$dbh = DBI->connect($connectionInfo,$userdb,$passwd);
 #open(FILE,"$rfile");
 open(FILE,"cyfence.pol");
 @DATA=<file>;</file>
 chomp(@DATA);
 #$x=$DATA[2];
 #print $x;
 print "
<table border=1 cellpadding=0 cellspacing=0><tr><td>Action</td><td>Disabled</td><td>Track</td><td>src</td><td>dst</td><td>Services</td></tr>";
 for ($i=0;$i
  #print $DATA[$i]."\n";
  if(($DATA[$i] ne ")") || ($DATA[$i] ne "(")){
  @x=split(/:/,$DATA[$i]);
  $m=0;
  @x=split(/ /,$x[1]);
  if($x[0] eq "header_text"){
    $header=$DATA[$i];
    @h=split(/"/,$header);
    $header=$h[1];
  }
  $tdst="
<table>";
  if($x[0] eq "rule"){
   $a=0;
   $dst="";
   $src="";
   $service="";
   $r=$x[0];
   $rule="
<tr>";
  }else{
   if($x[0] eq "track"){
    $t="track";
   }
   if($x[0] eq "dst"){
    $cdst=$x[0];
   }
   if($x[0] eq "services"){
    $cservices=$x[0];
   }
   if($x[0] eq "src"){
    $cservices="";
    $csrc=$x[0];
   }
   
   if(($x[0] eq "type") && ($r eq "rule")){
    $action=$x[1];
    $action=str_replace("(","",$action);
    $action=str_replace(")","",$action);
   }elsif($x[0] eq disabled){
    $dis=$x[1];
    $dis=str_replace("(","",$dis);
    $dis=str_replace(")","",$dis);
   }elsif(($x[0] eq "Name") && ($t eq "track")){
    $track=$x[1];
    $track=str_replace("(","",$track);
    $track=str_replace(")","",$track);
    $t="";
   }elsif(($x[0] eq "Name") && ($cdst eq "dst")){
    $dst=$dst."
</tr><tr><td>".$x[1]."</td></tr>";
    $dst=str_replace("(","",$dst);
    $dst=str_replace(")","",$dst);
    
   }elsif($x[0] eq "install"){
    $cdst="";
   }elsif(($x[0] eq "Name") && ($cservices eq "services")){
   #print $x[0]."---".$cservices."\n";
    $services=$services."
<tr><td>".$x[1]."</td></tr>";
    $services=str_replace("(","",$services);
    $services=str_replace(")","",$services);
   }elsif(($x[0] eq "Name") && ($csrc eq "src")){
    $src=$src."
<tr><td>".$x[1]."</td></tr>";
    $src=str_replace("(","",$src);
    $src=str_replace(")","",$src);
   }elsif($x[0] eq "through"){
    #print $csrc."\n";
    $cdst="";
    $cservices="";
    $csrc="";
    if($dis eq "true"){
    #print $header."\n";
     if($header ne ""){
      print "
<tr bgcolor=blue><td colspan=6>".$header."</td></tr>";
      }
     print "
<tr bgcolor=red><td>".$action."</td><td>".$dis."</td><td>".$track."</td><td><table>".$src."</table></td><td><table>".$dst."</table></td><td><table>".$services."</table></td></tr>";
     $header="";
    }else{
     print "
<tr><td>".$action."</td><td>".$dis."</td><td>".$track."</td><td><table>".$src."</table></td><td><table>".$dst."</table></td><td><table>".$services."</table></td></tr>";
     
    }
    #print $action."-".$dis."-".$track."-".$dst."-".$services."-".$src."\n";
    $dst="";
    $services="";
    $src="";
   }
  }
  
  
 }

 #print $rule."
</table>";
 }
 print "
</table>";
 #print $newfile."\n";
 #print $i;
 #print $llog."xxxxx\n";
}
&ReadFile();

วันพฤหัสบดีที่ 18 สิงหาคม พ.ศ. 2554

Perl Upload via FTP


#!/usr/bin/perl
 use Net::FTP;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon = $mon + 1;
$mday = $mday - 1;
$year = $year + 1900;
$logfile = "log.".$year."-".$mon."-".$mday.".txt";
#print $logfile;
    $ftp = Net::FTP->new("192.168.50.132", Debug => 0)
              or die "Cannot connect to some.host.name: $@";
    $ftp->login('user','password')
              or die "Cannot login ", $ftp->message;
#       $ftp->cwd("/log/")
#             or die "Cannot change working directory ", $ftp->message;
    $ftp->put("/log/$logfile")
              or die "get failed ", $ftp->message;
        $ftp->quit;
ประกาศเรียกใช้ Module นี้ก่อน use Net::FTP;
เอาวันเวลามา ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); เราต้องการอัพโหลด log file ย้อนหลังไปหนึ่งวัน โดยชื่อไฟล์จะเป็นฟอแมตดังนี้ log.2011-08-15.txt
เริ่มสร้าง Connection
$ftp = Net::FTP->new("192.168.50.132", Debug => 0)
              or die "Cannot connect to some.host.name: $@";
$ftp->login('user','password')
              or die "Cannot login ", $ftp->message;
แล้วก็สั่ง อัพโหลด
 $ftp->put("/log/$logfile")
              or die "get failed ", $ftp->message;
        $ftp->quit;
จบ >> แบบง่ายๆพอ 

วันจันทร์ที่ 6 มิถุนายน พ.ศ. 2554

Server Load Balancing ตอนที่ 1

ท่ามกลางระบบเครือข่ายขนาดใหญ่ รวมทั้งเครือข่ายที่ให้บริการอินเตอร์เน็ต การให้บริการข้อมูลข่าวสารแก่ผู้ใช้งานที่ร้องขอเข้ามาที่ Server พร้อมกันเป็นจำนวนมากเป็นเรื่องสุดวิสัยที่ Server ธรรมดาตัวหนึ่งจะสามารถกระทำได้ดังนั้น หนทางแก้ไขปัญหา คือการปรับปรุงระบบเครือข่ายให้มีประสิทธิภาพสูง แต่การปรับปรุงระบบเครือข่ายมิใช่คำตอบ เนื่องจากปัญหาอยู่ที่คอขวดภายใน Server ต่างหาก โดยส่วนใหญ่เป็นปัญหาของ ประสิทธิภาพการทำงานของ CPU และความเร็วของ Disk ตลอดจนหน่วยความจำที่จำกัดบน Server ส่งผลให้ Server หนึ่งตัว ไม่สามารถรองรับบริการจากผู้ใช้งาน ที่เข้ามาขอใช้บริการพร้อมกันเป็นจำนวนมาก ถึงแม้ว่าจะมีแนวทางแก้ไขปัญหา ดังกล่าง เช่น การติดตั้ง CPU หลายๆตัวบน Server เดียวกัน และทำงานในรูปแบบ Symmetric Multiprocessing(SMP) ก็ตาม ยังมีความยุ่งยากตรงที่ Application ที่จัดเขียนขึ้นจะตองให้บริการระบบดังกล่าว นอกจากนี้ ยังไม่ใช่คำตอบที่ให้ความสบายใจ 100% อย่างไรก็ดี แนวทางแก้ปัญหาดังกล่าว ได้แก่ การใช้งาน Server Load Balancing


รูปที่ 1 ลักษณะการเชื่อมต่อ Server Load Balancing

Server Load Balancing คืออะไร ?

Server Load Balancing เป็นกระบวนการทาง Software หรือการใช้ Hardware เพื่อแจกแจงหรือกระจายกระแสของข้อมูลข่าวสารไปยัง Server ต่างๆหลายตัวบนเครือข่ายพร้อมกัน โดยตัว Software หรือ Hardware นี้ จะทำหน้าที่สกัดการไหลเข้ามาของกระแสข้อมูลข่าวสารที่มีปลายทางอยู่ที่ Server ภายในเครือข่าย จากนั้นเปลี่ยนให้มุ่งตรงไปยัง Server ต่างๆหลายๆตัวพร้อมกัน โดยที่ผู้ใช้งานไม่ว่าจะอยู่บนเครือข่าย หรืออินเตอร์เน็ต จะไม่รับรู้ถึงการทำงานดังกล่าว นอกจากรู้สึกว่าสามารถได้รับข้อมูลข่าวสารได้อย่างรวดเร็ว โดยในแต่ละเครือข่ายที่เชื่อมต่อกับอินเตอร์เน็ต มักจะติดตั้ง Server ไว้หลายๆตัว บางแห่งมีมากกว่า 10 ตัวขึ้นไปต่อหนึ่ง URL โดย Server ต่างๆเหล่านี้ เชื่อมต่อกับอุปกรณ์ ทางด้าน Hardware หรือ Software ที่เราเรียกว่า Server Load Balancing รูปแบบของการเชื่อมต่อเป็นไปดังภาพที่ 1

หน้าที่การทำงานของ Server Load Balancing

Load Balancer สามารถทำหน้าที่ดังต่อไปนี้
  • สกัดกระแสของข้อมูลข่าวสารของเครือข่าย(กระแสข่าวสารเกี่ยวกับ Web) ที่มีปลายทางมายังเครือข่ายภายในที่ให้บริการ
  • แยกกระแสของข่าวสารออกเป็น หลายๆกระแสและตัดสินใจว่า แต่ละกระแสข่าวนี้ จะเดินทางไปที่ Server ตัวใดบ้าง
  • รักษาสถานการณ์ตรวจดูว่า Server ตัวใดที่กำลังใช้งานอยู่หรือว่างอยู่ เพื่อให้สามารถตอบสนองต่อผู้ที่ขอใช้งานเข้ามาได้อย่างรวดเร็ว และมีรูปแบบหมุนเวียนผลัดเปลี่ยนกันไป
  • มีรูปแบบการทำงานแบบ Fail-Over กล่าวคือสามารถทำงานในรูปแบบทดแทนกัน ในกรณีที่ Server ตัวใดตัวหนึ่งไม่ทำงาน
  • สามารถสกัดกั้น Cookies อ่าน URL เป็นต้น
เหตุใดจึงต้องใช้ Server Load Balancing

หากท่านมี Web Server เพียงหนึ่งตัวเพื่อตอบสนอง การเข้ามาของข้อมูลเกี่ยวกับ HTTP WEB Services จากผู้ใช้งานทั่วไปทุกสารทิศ แน่นอน Web Server ของท่านไม่สามารถรองรับการร้องขอข้อมูลได้ การให้บริการข้อมูลของ website จะดำเนินไปอย่างล่าช้า และผู้ใช้งาน อาจต้องรอให้ Web Server ว่างลงเสียก่อนจึงสามารถโหลดข้อมูลได้อย่างรวดเร็วตามปกติ

เพื่อให้สามารถรองรับต่อความต้องการ มีการเพิ่มจำนวนของ Server เข้าเป็นกลุ่มขนาดใหญ่ ซึ่งเราเรียกว่า Server Cluster และการกระจายของข้อมูลที่ผู้ใช้งาน ร้องขอเข้ามาจากที่ต่างๆ จะถูกนำส่งกระจายไปตาม Server ต่างๆ ด้วยวิธีที่เรียกว่า Load Balancing

กลไกการทำงานของ Load Balancing

เมื่อใดที่มีการติดตั้ง Web Server เป็นกลุ่มขึ้น จำเป็นต้องมีวิธีการกระจายกระแสข่าวสารเกี่ยวกับ HTTP ไปที่ Server ต่างๆโดยที่ Server เหล่านี้ จะต้องถูกทำให้ปรากฏตัวเพียงหนึ่งเดียวแก่ผู้ขอใช้บริการเข้ามา โดยเฉพาะการปรากฏตัวบน Web Browser ของผู้ใช้บริการ กลไกการกระจายตัวของกระแสข้อมูลข่าวสารไปที่ Server ต่างๆเราเรียกว่า การพ่นกระจายของไอพี หรือ IP Spraying

การร้องขอข้อมูลภายใต้ HTTP ถูกเรียกว่า IP Spraying โดยมีอุปกรณ์ที่ใช้ในการนี้ เรียกว่า Load Dispatcher หรือ Network Dispatcher หรือที่นิยมเรียกว่า "Load Balancer"

ในกรณีนี้ ระบบ IP Spraying จะทำหน้าที่สกัดกระแสของข่าวสาร HTTP ที่เข้ามา จากนั้นเบนเข็มไปยัง Server ที่เชื่อมต่อกันแบบ Cluster รูปแบบการทำ IP Spraying มีหลายประการ โดยแต่ละแบบจะให้ขีดความสามารถในการขยาย หรือให้บริการทำงานทดแทน

 คราวหน้าเราจะกล่าวถึงชนิดของ Load Balancing ...โปรดติดตาม Server Load Balancing ตอนที่ 2 ครับ

วันศุกร์ที่ 3 มิถุนายน พ.ศ. 2554

จัดการกับไฟล์ด้วย VBScript

เราสามารถที่จะ add, move, change, create, or delete folders  สคริปจะยอมให้เราจัดการกับ drives, folders, and files โดยใช้ Object ที่ชื่อว่า FileSystemObject (FSO)   FSO Object จะเรียกใช้ไลบรารี่ (Scrrun.dll), สนับสนุนการสร้างและการจัดการแฟ้มข้อความผ่าน TextStream วัตถุ
ก่อนอื่นเราต้องสร้างออปเจ็ค FileSystemObject โดยใช้ CreateObject method.
ตัวอย่าง

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject") 
Scripting คือชื่อประเภทของไลบรารี่และ FileSystemObject คือชื่อของออปเจ็คที่เราต้องการสร้าง
ลำดับต่อมาคือการใช้ Method ของ FileSystemObject ตัวอย่างเช่น Create ออปเจ็คก็จะมี CreateTextFile or CreateFolder

ดูตัวอย่างที่ใช้งานกันก่อนดีกว่า Script  ด้านล่างนี่คือเราจะทำการ Move ไฟล์จาก C:\tmp\ ไปไว้ที่ C:\test\ และทำการเปลี่ยนชื่อไฟล์เป็นวันที่ LastModified เช็ควันที่ LastModified และ Extention ด้วย

OPTION EXPLICIT
DIM strExtensionsToCopy,strFolder
DIM objFSO, MaxAge, IncludeSubFolders,desFolder

' ************************************************************
' Setup
' ************************************************************
strFolder="C:\tmp\"
desFolder="C:\test\"

' Copy files from sub-folders?
includeSubfolders = true
' A comma separated list of file extensions
' Files with extensions provided in the list below will be copy
strExtensionsToCopy = "txt,temp"
' Max File Age (in Days).  Files older than this will be copy.
maxAge = 1

' ************************************************************

set objFSO = createobject("Scripting.FileSystemObject")

CopyFiles strFolder,strExtensionsToCopy, maxAge, includeSubFolders

sub CopyFiles(byval strDirectory,byval strExtensionsToCopy,byval maxAge,includeSubFolders)
                DIM objFolder, objSubFolder, objFile
                DIM strExt

                set objFolder = objFSO.GetFolder(strDirectory)
                for each objFile in objFolder.Files
                                for each strExt in SPLIT(UCASE(strExtensionsToCopy),",")
                                                if RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = "." & strExt then
                                                                IF objFile.DateLastModified > (Now - MaxAge) THEN
                                                                                objFile.Move Replace(objFile.Path,objFile.Name,pd(day(objFile.DateLastModified),2) & pd(month(objFile.DateLastModified),2) & year(objFile.DateLastModified) & pd(hour(objFile.DateLastModified),2) & pd(minute(objFile.DateLastModified),2) & "." & strExt)
                                                                                objFile.move desFolder
                                                                                exit for
                                                                END IF
                                                end if
                                next
                next     
end sub
Function pd(n, totalDigits)
        if totalDigits > len(n) then
            pd = String(totalDigits-len(n),"0") & n
        else
            pd = n
        end if
End Function

ยังมีเรื่องเล่าอีกเยอะสำหรับ  FileSystemObject แล้วจะทยอยนำมาเล่าอีกเรื่อยนะครับ

OZone & Ultra

วันพุธที่ 1 มิถุนายน พ.ศ. 2554

พบช่องโหว่ Microsoft Windows Live Messenger

Microsoft Windows Live Messenger 'dwmapi.dll' DLL Loading Arbitrary Code Execution Vulnerability


มีผลกระทบกับ 
Microsoft Windows Live Messenger 14.0.8089
Microsoft Windows Live Messenger 14.0.8117.416
Microsoft Windows Live Messenger 14.0
Microsoft Windows Live Messenger 0



Microsoft Windows Live Messenger มีแนวโน้มที่จะเสี่ยงที่ช่วยให้ผู้โจมตีทำการรันโค้ด

ผู้บุกรุกสามารถใช้ประโยชน์จากปัญหานี้ได้โดยใช้โปรแกรมที่มีช่องโหว่ในการเปิดไฟล์จากเครือข่ายที่มีการเชื่อมโยงแบบ 
Dynamic Linked Library (DLL)


exploit


/data/vulnerabilities/exploits/48055.c


การแก้ไข :
ขณะนี้เราไม่ทราบของแพทช์ได้จากผู้ขายใด ๆ



เอกสารอ้างอิง
ที่มา:Security Focus
Bugtraq ID :48055
Published:May 31 2011 12:00AM
Updated:May 31 2011 12:00AM
Credit:Kalashinkov3