Perl·Î ÇÏµå µå¶óÀ̺긦 ¾ÈÀüÇÏ°Ô Áö¿ì±â

[æ», À±ºÀȯ el@linuxlab.co.kr]
¿ø¹® : Mark Nielsen, translate into korean: electuz(el@kldp.org)

 

     

    Contents

             µé¾î°¡¸ç
             ¹®Á¦µé
             ÆÞ ½ºÅ©¸³Æ®
             ¸ÎÀ¸¸ç
             Âü°í¹®Çå

 

µé¾î°¡¸ç

    ¿ÀÇÏÀÌ¿À¿¡¼­ Ķ¸®Æ÷´Ï¾Æ·Î ¿Å±æ ¶§, GNUJobs.com¿¡´Â COLUG(http://www.colug.net/, Central Ohio Linux Users Group)¿¡ ±âÁõÇÏ·Á´Â ÇÏµå µå¶óÀÌºê ¸î °³¸¦(´Ù¸¥ Çϵå¿þ¾î, ¼ÒÇÁÆ®¿þ¾î¿Í ÇÔ²²) °¡Áö°í ÀÖ¾ú½À´Ï´Ù. ±×¸®°í, ÇÏµå µå¶óÀ̺êµéÀ» ±âÁõÇϱâ Àü¿¡ ±× ³»¿ëÀ» Áö¿ö¾ß Çß½À´Ï´Ù. ÇÏµå µå¶óÀÌºê ¼Â Áß¿¡ µÑÀº ¹èµå ¼½Å͸¦ °¡Áö°í ÀÖ¾ú½À´Ï´Ù. ±×·¡¼­, ÀÌ ±â»ç¸¦ ¸¸µå´Â °Íó·³ Å×½ºÆ®ÇÒ ¸ñÀûÀ¸·Î, ¸¶Áö¸·À¸·Î ³²Àº ¼¼ ¹ø° ÇÏµå µå¶óÀ̺긦 »ç¿ëÇÏ°Ô µÇ¾ú°í, °á±¹ ´©±¸¿¡°Ô ÁÙ°Ô ³²Áö ¾Ê¾Ò½À´Ï´Ù. ¾Æ¹«Æ°, ÀÌ °Í»Ó¸¸ ¾Æ´Ï¶ó, ¾ÕÀ¸·Îµµ ÇÏµå µå¶óÀ̺긦 ±ú²ýÀÌ Áö¿ö¾ß ÇÒ ÀϵéÀÌ »ý±æ Å×°í, ±×·¡¼­ ³ª´Â ÀÌ ÆÞ(Perl) ½ºÅ©¸³Æ®¸¦ ¸¸µé°Ô µÇ¾ú½À´Ï´Ù (´ÙÀ½¿¡ ³ª´Â ÆÄÀ̽ã-PythonÀ¸·Î ¹Ù²Ù°í, ´õ ¸¹Àº ¿É¼ÇµéÀ» ³ÖÀ¸·Á ÇÕ´Ï´Ù)

    ÀÌ ÆÞ ½ºÅ©¸³Æ®ÀÇ ¸ñÀûÀº ±×Àú /dev/hdb¿¡(ÁÖ IDE ÄÁÆ®·Ñ·¯¿¡ ¿¬°áµÈ ½½·¹ÀÌºê µå¶óÀ̺ê) ÀÖ´Â ÇÏµå µå¶óÀ̺긦(³»¿ëÀ») Áö¿ì·Á´Â °ÍÀÔ´Ï´Ù. ³ª´Â ÀÌ ½ºÅ©¸³Æ®·Î ¸ðµç ÆÄƼ¼ÇµéÀ» Áö¿ì°í, ÇÏµå µå¶óÀ̺ê Àüü¸¦ Â÷ÁöÇÏ´Â Ä¿´Ù¶õ ÆÄƼ¼ÇÀ» ¸¸µç ´ÙÀ½ ±× ÆÄƼ¼ÇÀ» ¾²·¹±â µ¥ÀÌÅÍ·Î(¹«½¼ µ¥ÀÌÅÍÀÎÁö ã¾Æ³»·Á°í ¾Ö¾²´Â µ¿¾È, ÇØÄ¿ÀÇ ÇÏ·ç°¡ ¸ô¶ôÇϵµ·Ï, ¸¶±¸ÀâÀÌ·Î ¾ÏȣȭµÈ ÀÇ¹Ì ¾ø´Â µ¥ÀÌÅ͵éÀ» ³Ö¾î¼­) °¡µæ ä¿ì·Á°í ÇÕ´Ï´Ù.

 

¹®Á¦µé

    ³»°¡ ¸¸³­ ¹®Á¦µé°ú ±× °ÍÀ» ÇØ°áÇÑ ¹æ¹ýÀÔ´Ï´Ù:

    1. ¾î¶»°Ô ÇÏ¸é ½ºÅ©¸³Æ®°¡ ¸ðµç ÆÄƼ¼ÇÀ» Áö¿ï ¼ö ÀÖÀ»±î?

    ³ª´Â ÇÏµå µå¶óÀ̺꿡¼­ ÆÄƼ¼ÇÀ» ¹Ù²Ù±â À§ÇÑ ¸¹Àº ´Ù¸¥ ¿É¼ÇµéÀ» ã¾Æº¸¾ÒÀ¸¸ç Á÷Á¢ ±×·± °ÍµéÀ» »ç¿ëÇßÀ» ¶§ ÃÖÀûÀÇ °á°úµéÀ» °¡Á®¿Ô´ø °ÍÀ» ¶°¿Ã·È½À´Ï´Ù. Àü¿¡ fdisk ÇÁ·Î±×·¥À» (fdisk´Â ¸®´ª½º¿¡¼­ ÇÏµå µå¶óÀ̺ê ÆÄƼ¼ÇÀ» ÆíÁýÇÏ´Â µµ±¸ÀÔ´Ï´Ù) ÀÚµ¿È­ÇÏ´Â µ¥ Perl Expect ½ºÅ©¸³Æ®¸¦ »ç¿ëÇß¾ú°í, À̹ø¿¡µµ ±× ¹æ¹ýÀ» »ç¿ëÇϱâ·Î ¸¶À½ ¸Ô¾ú½À´Ï´Ù. ³ª´Â sfdisk¿Í ´Ù¸¥ °Íµéó·³ °£´ÜÇÏ°Ô ¸ðµç ÆÄƼ¼ÇÀ» Áö¿ì´Â µµ±¸·Î ¹Ù²Ù´Â °ÍÀÌ ´õ ³ªÀ» °ÍÀ̶ó »ý°¢ÇßÁö¸¸, ÇÑ ¼Ö·ç¼ÇÀÌ 100% ÆÄ¿ö¿Í À¯¿¬¼ºÀ¸·Î ¸ðµç °¡´É¼ºÀ» ¶°¸Ã´Â´Ù¸é, ÇÏ·Á´Â ÀÏ¿¡ ´ëÇØ ÇÑ °¡Áö ¹æ¹ý¿¡¸¸ ¸Å´Þ¸± °ÍÀÌ°í, ±×·¯¸é ³Ê¹« ¸¹Àº °Íµé¿¡ ´ëÇؼ­ ±â¾ïÇÒ ÇÊ¿ä°¡ ¾øÀ» Å×°í, ´õ º¹ÀâÇÑ °ÍµéÀ» ¸¸³ª°Ô µÇ¾îµµ, »õ·Î ¹è¿ö¾ß ÇÒ °ÍÀº ¾Æ¹« °Íµµ ¾øÀ» °ÍÀÔ´Ï´Ù.

    ±×·¯¹Ç·Î ³ª´Â »ç¿ëÀÚ°¡ fdisk¿¡¼­ ¸í·ÉÇÏ´Â °ÍÀ» Èä³» ³»´Â Expect Äڵ带 »ç¿ëÇß½À´Ï´Ù. Expect ÄÚµå´Â fdisk¸¦ ÀÌ¿ëÇؼ­ ÀÚµ¿À¸·Î ¸ðµç ÆÄƼ¼ÇÀ» Áö¿ü°í, »õ·Î Å« ÆÄƼ¼ÇÀ» Çϳª ¸¸µé¾ú½À´Ï´Ù.

    2. ÇÏµå µå¶óÀ̺긦 ¾²·¹±â µ¥ÀÌÅÍ·Î °¡µæ ä¿ì´Â ¹æ¹ýÀº?

    ÆÄƼ¼ÇÀ» »èÁ¦ÇÒ ¶§¿¡ ´ÜÁö µ¥ÀÌÅ͸¸ Áö¿ö¼­´Â ¸ðÀÚ¶ø´Ï´Ù. ³ª´Â Áö³­ µ¥ÀÌÅÍ À§¿¡ ¾²·¹±â µ¥ÀÌÅ͸¦ µ¤¾î½á¼­, ÀÌÀü µ¥ÀÌÅÍ°¡ ¿ÏÀüÇÏ°Ô Áö¿öÁö°Ô ¸¸µé·Á°í ÇÕ´Ï´Ù. ³ª´Â ÆÄƼ¼ÇÀ» ¸¸µé°í Å©±â¸¦ Á¤Çϱâ À§ÇØ fdisk¸¦ »ç¿ëÇß½À´Ï´Ù. ±× ´ÙÀ½, ¾²·¹±â µ¥ÀÌÅÍ°¡ »õ·Î »ý¼ºµÈ ÆÄƼ¼Ç Å©±âº¸´Ù Å©°Å³ª °°¾ÆÁú ¶§±îÁö °è¼ÓÇؼ­ Ãâ·ÂÇÏ´Â ·çÇÁ¸¦ ¸¸µé¾ú½À´Ï´Ù.

    3. ÇÏµå µå¶óÀ̺꿡 ÇØÄ¿¸¦ ³î¸®±â À§ÇÑ ¹ÙÀ̳ʸ® µ¥ÀÌÅÍ´Â ¾î¶»°Ô ³ÖÀ»±î?

    ³ª´Â Perl¿¡ ÀÖ´Â random ÇÔ¼ö¿Í ¡°chr¡± ÇÔ¼ö¸¦ ÀÌ¿ëÇؼ­ ·£´ý ¹ÙÀ̳ʸ® µ¥ÀÌÅ͸¦ ¸¸µé¾ú½À´Ï´Ù. ±× ´ÙÀ½, Perl Blowfish ¸ðµâÀ» ÀÌ¿ëÇؼ­ ·£´ý µ¥ÀÌÅ͸¦ ¾ÏȣȭÇß½À´Ï´Ù. ´©±º°¡ ±× µ¥ÀÌÅ͸¦ ¿ëÄÉ Çص¶Çس´ٸé, ¾öû³­ ³ë·Â¿¡µµ ºÒ±¸ÇÏ°í ¿©ÀüÈ÷ ¾²·¹±âó·³ º¸ÀÌ´Â µ¥ÀÌÅÍµé ¶§¹®¿¡ ¾î¸®µÕÀýÇÒ °ÍÀÔ´Ï´Ù. ³ª´Â ¼öÇÐÀûÀÎ ¸é¿¡¼­ ¿ÏÀüÈ÷, ¸¶±¸ÀâÀÌ·Î(random) ¸¸µé¾îÁø °Íó·³ º¸ÀÌÁö ¾Ê°Ô (¾à°£ÀÇ ±ÔÄ¢¼ºÀ» ³Ö¾î¼­) ¾ÏȣȭÇÏ°í ½Í¾ú½À´Ï´Ù.

    4. Å« ÆÄƼ¼Ç ÀçÆ÷¸ËÀº ¾î¶»°Ô ÇÒ±î?

    ½±½À´Ï´Ù. ³ª´Â ±×Àú °£´ÜÈ÷ ¡°mkfs¡± ¸í·É¸¸ »ç¿ëÇß½À´Ï´Ù.

 

Perl ½ºÅ©¸³Æ®

    ³»°¡ Perl ½ºÅ©¸³Æ®¿¡ »ç¿ëÇÑ Perl ¹öÀüÀº ±¸½ÄÀ̾ú½À´Ï´Ù. Perl 5.005_03 ¹öÀüÀ» »ç¿ëÇÏ°í ÀÖ¾ú´Âµ¥, ³»°¡ ¾Ë±â·Î PerlÀº 2001³â 1¿ù¿¡ 5.6À¸·Î ¹öÀüÀÌ ¿Ã¶ú½À´Ï´Ù.

    »ç¿ëÀÚ¿¡°Ô ´õ ¼Õ½¬¿î ½ºÅ©¸³Æ®¸¦ ¸¸µé±â À§Çؼ­´Â ±â´ÉÀ» °­È­ÇØ¾ß ÇÒ °ÍµéÀÌ ¸¹ÀÌ ÀÖ½À´Ï´Ù. ´õ ¸¹Àº ¿¡·¯ °Ë»ç¿Í ½ºÅ©¸³Æ®°¡ °¡Áø À§Ç輺¿¡ ´ëÇÑ °íÂûÀÌ ÀÖ¾î¾ß Çϸç, ±×µéÀÌ Á¤¸» ±×·¸°Ô ä¿ö ³ÖÀ¸·Á ÇÑ´Ù¸é »ç¿ëÀڵ鿡°Ô ±×·± Áú¹®À» º¸¿©Áà¾ß ÇÒ °ÍÀÔ´Ï´Ù. ³ª´Â ÀÌ ½ºÅ©¸³Æ®¸¦ ´õ Çâ»ó½ÃÅ°¿¡ ¾Õ¼­ ³» MILAS ÇÁ·ÎÁ§Æ®(æ»ñÉ:MILAS Installs Linux And Stuff ÇÁ·ÎÁ§Æ®´Â Mark NeilsenÀÌ Áö³­ÇغÎÅÍ °ø¾ðÇØ¿Â ÀÏ·ÃÀÇ ÇÁ·ÎÁ§Æ®ÀÔ´Ï´Ù. NielsenÀº ·çÆ® ÆÄÀϽýºÅÛÀÌ Æ÷ÇÔµÈ ÀνºÅç CD µî ¸¹Àº ±ÛÀ» ±×µ¿¾È ½á ¿Ô½À´Ï´Ù, Perl·Î °èȹÇß´ø ÀÌ ÇÁ·ÎÁ§Æ®¸¦ PythonÀ¸·Î ´Ù½Ã ¾²°Å³ª »õ·Î ¸¸µç´Ù°í ÇÕ´Ï´Ù) Àç½ÃÀÛÀ» ÁغñÇÏ°í ÀÖ½À´Ï´Ù.
    ³ª´Â Äڵ忡 ÁÖ¼®À» ¸¹ÀÌ ºÙ¿´½À´Ï´Ù. ±×·¯¹Ç·Î À߸¸Çϸé Dz³»±â ÇÁ·Î±×·¡¸ÓµéÀÌ¶óµµ ³» Àǵµ¸¦ °ÅÀÇ ÀÌÇØÇÒ ¼ö ÀÖÀ» °ÍÀÔ´Ï´Ù.
     

    -------------------------------------------------------start of script

    #!/usr/bin/perl

    ##### ÇÒ Àϵé
    # 1. ´©±º°¡ ·Î±×ÀÎ µÉ °æ¿ì º¸¾È À§ÇèÀ» ÇÇÇϱâ À§ÇØ
    #     Àӽ÷Π¸¶¿îÆ® ÇÒ »õ·Î¿î µð·ºÅ丮¸¦ ¸¸µé°í Æ۹̼ÇÀ» ¹Ù²ß´Ï´Ù.
    # 2. ¸¹Àº ½Ã½ºÅÛ ÄݵéÀ» ´Ù·ç±â À§ÇØ perl ÇÔ¼ö¸¦ »ç¿ëÇÕ´Ï´Ù.
    # 3. ÇÏµå µå¶óÀ̺êµé°ú Ç÷ÎÇÇ µå¶óÀ̺êµéÀ» ÀÚµ¿À¸·Î ã°Ô ÇÏ°í,
    #     ¸¶¿îÆ®µÇÁö ¾ÊÀº ÇÏµå µå¶óÀ̺êµé°ú Ç÷ÎÇÇ µå¶óÀ̺꿡¼­¸¸ ÀÛµ¿Çϵµ·Ï ¸¸µì´Ï´Ù.
    #####

    use strict;
    use Expect;
    use Crypt::Blowfish;

    #-----------------------------------------------
    my $Junk;

      ### Primary IDE ÄÁÆ®·Ñ·¯¿¡ ¿¬°áµÈ ½½·¹ÀÌºê µå¶óÀ̺긦 º¯¼ö $Drive¿¡ ³Ö½À´Ï´Ù.
    my $Drive = ¡°hdb¡±;

      ### ¸¶±¸ÀâÀÌ·Î ¸¹Àº °ÍµéÀ» ä¿ö ³Ö°Ô ÇÏ°í,
      ### Á¤¸» ¸¶±¸ÀâÀÌ·Î ¸¸µé±â À§ÇØ
      ### /etc/passwd ÆÄÀÏ¿¡¼­ ¸¶Áö¸· ÁÙÀ» °¡Á®¿Í¼­,
      ### ÄÄÇ»ÅÍ¿¡ ÇÑ »ç¶÷ÀÌ Ãß°¡µÈ °ÍÀ¸·Î °¡Á¤ÇÕ´Ï´Ù.
    my $time = time();
    my $Ran = rand($time);
    my $Ran = rand(10000000000000);
    my $LastLine = ¡®tail -n 1 /etc/passwd¡¯; chomp $LastLine;
    $LastLine = substr ($LastLine,0,30);
    my $Blowfish_Key = $LastLine . $Ran . $time;
    $Blowfish_Key = substr ($Blowfish_Key,0,20);
    while (length ($Blowfish_Key) < 56)
      {
      $Blowfish_Key .= $Ran = rand($time);
      }
    $Blowfish_Key = substr ($Blowfish_Key,0,56);

      ### ·£´ý Å° ¸¸µé±â¸¦ ¸¶Ä¡°í, ÀÌÁ¦ Blowfish ¾ÏÈ£ °³Ã¼¸¦ ¸¸µì´Ï´Ù.
    my $Blowfish_Cipher = new Crypt::Blowfish $Blowfish_Key;

    #------------------------------------
    system ¡°clear¡±;
    #print ¡°This will wipe out the hard drive on Drive /dev/$Drive¡¬n¡±;
    print ¡°µå¶óÀ̺ê /dev/$Drive¡¬n¿¡¼­ ÇÏµå µå¶óÀ̺긦 ±ú²ýÀÌ Ã»¼ÒÇÕ´Ï´Ù¡±;
    #print ¡°Press enter to continue¡¬n¡±;
    print ¡°¾Æ¹« Å°³ª ´©¸£¼¼¿ä.¡¬n¡±;
    my $R = <STDIN>;

      ### û¼ÒÇÏ·Á´Â µå¶óÀ̺꿡¼­ ¸¶¿îÆ®µÈ ÆÄƼ¼Ç ¸ñ·ÏÀ» ÀоîµéÀÔ´Ï´Ù.
    my @Mounted = ¡®df¡¯;
    @Mounted = grep($_ =~ /¡¬/dev¡¬/hdb/, @Mounted);

      ### umount ¸íÇüÀ¸·Î ¸¶¿îÆ®µÈ ÆÄƼ¼ÇÀ» ¸ðµÎ ÇØÁ¦ÇÕ´Ï´Ù.
    foreach my $Mount (@Mounted)
      {
      my ($Partition,$Junk) = split(/¡¬s+/, $Mount,2);
      #print ¡°Unmounting $Partition¡¬n¡±;
      print ¡°¸¶¿îÆ®¸¦ ÇØÁ¦ÇÕ´Ï´Ù: $Partition¡¬n¡±;
      my $Result = system (¡°umount $Partition¡±);
      if ($Result > 0)
        {
        #print ¡°ERROR, unable to umount $Partition, aborting Script, Error = $Result¡¬n¡±;
        print ¡°ERROR, $Partition ÆÄƼ¼ÇÀ» umountÇÒ ¼ö ¾ø½À´Ï´Ù, ½ºÅ©¸³Æ® ½ÇÇàÀ» Ãë¼ÒÇÕ´Ï´Ù, Error = $Result¡¬n¡±;
        exit;
        }
      }

      ### ´©±º°¡ fdisk ¸í·ÉÀ» »ç¿ëÇÏ°í ÀÖ´Â °Íó·³ Èä³»³»´Â expect ½ºÅ©¸³Æ®¸¦ ½ÃÀÛÇÕ´Ï´Ù.
    my $Fdisk = Expect->spawn(¡°/sbin/fdisk /dev/$Drive¡±);

      ### ÆÄƼ¼Ç Å×À̺íÀ» Ãâ·ÂÇؼ­ ¸¶¿îÆ®µÈ ÆÄƼ¼Ç ¸ñ·ÏÀ» ¾ò½À´Ï´Ù.
    print $Fdisk ¡°p¡¬n¡±;
    my $match=$Fdisk->expect(30,¡°Device Boot    Start¡±);

    my $Temp = $Fdisk->exp_after();
    my @Temp = split(/¡¬n/, $Temp);
      ## ÆÄƼ¼Ç¿¡ ´ëÇØ ¿ì¸®¿¡°Ô ¸»ÇØÁÖ´Â ¶óÀεéÀ» ÃßÃâÇÕ´Ï´Ù.
    my @Partitions = grep($_ =~ /^¡¬/dev¡¬//, @Temp);
      ## °¢ ¶óÀÎÀ» ÀÌ¿ëÇؼ­ ÆÄƼ¼ÇÀ» Áö¿ó´Ï´Ù.
    foreach my $Line (reverse @Partitions)
      {
        ## /dev/hdb ºÎºÐ°ú ¼ýÀÚµéÀ» °¡Á®¿É´Ï´Ù.
      my ($Part,$Junk) = split(/[¡¬t ]/, $Line,2);
      my $No = $Part;
      $No =~ s/^¡¬/dev¡¬/$Drive//;

      #print ¡°Deleting no $Drive $No¡¬n¡±;     
      print ¡°¹øÈ£ $Drive $NoÀ» Áö¿ó´Ï´Ù¡¬n¡±;     

        ## Áö¿ì´Â ¸í·É
      print $Fdisk ¡°d¡¬n¡±;    
      $match=$Fdisk->expect(30,¡°Partition number¡±);
       
        ## Áö¿ì·Á´Â ÆÄƼ¼Ç ¹øÈ£
      print $Fdisk ¡°$No¡¬n¡±;
      $match=$Fdisk->expect(30,¡°Command (m for help):¡±);
      }

    $Fdisk->clear_accum();

      ### ÆÄƼ¼ÇÀÌ ÀÖÀ¸¸é ¹Ù²ã ¾²°í ±×·¸Áö ¾Ê´Ù¸é, ±×³É ³¡³À´Ï´Ù.

    if (@Partitions < 1) {print $Fdisk ¡°q¡¬n¡±; $Fdisk->expect(2,¡°:¡±);}
    else
      {
      print $Fdisk ¡°w¡¬n¡±;
      $Fdisk->expect(30,¡°Command (m for help):¡±);
      }

    #-------------------------------
      ## ÇÏµå µå¶óÀ̺ê Áö¿À¸ÞÆ®¸®¸¦ ±¸ÇÕ´Ï´Ù.
    my $Geometry = ¡®/sbin/sfdisk -g /dev/$Drive¡¯;
    my ($Junk, $Cyl, $Junk2, $Head, $Junk3, $Sector,@Junk) = split(/¡¬s+/,$Geometry);
    if ($Cyl < 1)
       #{print ¡°ERROR: Unable to figure out cylinders for drive. aborting¡¬n¡±; exit;}
       {print ¡°ERROR: µå¶óÀ̺꿡¼­ ½Ç¸°´õ ¼ö¸¦ °è»êÇÒ ¼ö ¾ø½À´Ï´Ù. ½ÇÇàÀ» Ãë¼ÒÇÕ´Ï´Ù.¡¬n¡±; exit;}

      ### »ç¶÷ÀÌ fdisk¸¦ »ç¿ëÇÏ´Â °Íó·³ Èä³»³»±â À§ÇØ »õ·Î¿î expect ½ºÅ©¸³Æ®¸¦ ¸¸µì´Ï´Ù.
    my $Fdisk = Expect->spawn(¡°/sbin/fdisk /dev/$Drive¡±);

       #### fdisk¿¡ »õ ÆÄƼ¼ÇÀ» ¸¸µå´Â ¸í·ÉÀ» Àü´ÞÇÕ´Ï´Ù.
    print $Fdisk ¡°n¡¬n¡±;
    $Fdisk->expect(5,¡°primary¡±);

      ### »õ·Î¿î ÆÄƼ¼ÇÀÌ primary ÆÄƼ¼ÇÀ̶ó°í ¸»ÇØ ÁÝ´Ï´Ù.
    print $Fdisk ¡°p¡¬n¡±;
    $Fdisk->expect(5,¡°:¡±);

      ### »õ·Î¿î ÆÄƼ¼Ç¿¡ ¹øÈ£ 1À» ÇÒ´çÇÕ´Ï´Ù.
    print $Fdisk ¡°1¡¬n¡±;
    $Fdisk->expect(5,¡°:¡±);

      ### ½Ç¸°´õ ¹øÈ£ 1¿¡¼­ ½ÃÀÛÇÕ´Ï´Ù.
    print $Fdisk ¡°1¡¬n¡±;
    $Fdisk->expect(5,¡°:¡±);

      ### ½Ç¸°´õ ³¡±îÁö ÆÄƼ¼Ç¿¡ ÇÒ´çÇÕ´Ï´Ù.
    print $Fdisk ¡°$Cyl¡¬n¡±;
    $Fdisk->expect(5,¡°:¡±);

      ### ±â·ÏÇÏ°í ÀúÀåÇÕ´Ï´Ù.
    print $Fdisk ¡°w¡¬n¡±;
    $Fdisk->expect(30,¡°Command (m for help):¡±);

    #------------------------------------------
    ### ÆÄƼ¼ÇÀ» Æ÷¸ËÇÏ°í ¸¶¿îÆ®ÇÕ´Ï´Ù.

    my $Partition = ¡°/dev/$Drive¡± . ¡°1¡±;
    my $Result = system (¡°mkfs -t ext2 $Partition¡±);
    if ($Result > 0) {print ¡°Error making partition, aborting.¡¬n¡±; exit;}

       ### ¿¡·¯°¡ üũµÇ¸é ´õ ÁÁ½À´Ï´Ù.
    system ¡°umount /tmp/WIPE_IT¡±;
    system ¡°rm -rf /tmp/WIPE_IT¡±;
    system ¡°mkdir -p /tmp/WIPE_IT¡±;
    system ¡°chmod 700 /tmp/WIPE_IT¡±;

      ## ¿ì¸®°¡ »õ ÆÄƼ¼ÇÀ» ¸¶¿îÆ® ÇÒ ¼ö ÀÖ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
    my $Result = system (¡°mount $Partition /tmp/WIPE_IT¡±);
    #if ($Result > 0) {print ¡°Error mounting drive, aborting.¡¬n¡±; exit;}
    if ($Result > 0) {print ¡°µå¶óÀ̺긦 ¸¶¿îÆ®ÇÒ ¼ö ¾ø½À´Ï´Ù, ½ÇÇàÀ» Ãë¼ÒÇÕ´Ï´Ù.¡¬n¡±; exit;}
    system ¡°chmod 700 /tmp/WIPE_IT¡±;

    #--------------------------------
    ### ÀÌÁ¦ ÆÄÀÏÀ» ¸¸µé°í Å©±â¸¦ ¸ÂÃß¾úÀ» ¶§ ¸ØÃä´Ï´Ù.

    my $Count = 0;
    my $Written_Size = 0;  

      ### »õ ÆÄÀÏÀ» ¿±´Ï´Ù.
    open(FILE,¡°>>/tmp/WIPE_IT/Message.txt¡±);
       ### ´©±º°¡ ½ÇÁ¦·Î ¿©·¯ºÐÀÇ ÇÏµå µå¶óÀ̺ê ÁÖº¯À» ¾î½½··°Å¸®·Á ÇÑ´Ù¸é,
       ### Ç®±â ¾î·Á¿î Àå³­°¨À» Çϳª º¸Å¼­
       ### ÇÏµå µå¶óÀ̺꿡¼­ ³î°Ô ÇØÁÖ´Â ´ë½Å ÀڽŵéÀÇ ½Ã°£À» ÇãºñÇÏ°Ô ¸¸µì´Ï´Ù.
    my $Ran = rand 259200000;   # Áö±ÝºÎÅÍ 10³âÂë Àü±îÁö(´ë·«)
    ($Ran, $Junk) = split(/¡¬./, $Ran, 2);
       ## »õ·Î¿î ³¯Â¥´Â À½¼öÀÎ ÃÊ·Î »ý¼ºÇÕ´Ï´Ù
    my $Date = ¡®date --date ¡®-$Ran seconds¡¯¡¯;

    print FILE ¡°DATE CREATED $Date¡¬n¡±;
    my $Ran = rand 50;
    ($Ran, $Junk) = split(/¡¬./, $Ran, 2);
    $Ran = $Ran + 10;
    #print FILE ¡°This document is extremely secure. It is a violation to let
    #any unauthorized persons read it. Known password holders need to
    #apply Method $Ran in order to decrypt binary data.¡¬n¡±;
    print FILE ¡°ÀÌ ¹®¼­´Â öÀúÇÑ ºñ¹ÐÀ̸ç Çã°¡¹ÞÁö ¾ÊÀº ÀÌ°¡ ÀÌ ¹®¼­¸¦ Àо´Â ¾ÈµË´Ï´Ù.
    Æнº¿öµå¸¦ ¾Ë°í ÀÖ´Ù¸é ¹ÙÀ̳ʸ® µ¥ÀÌÅ͸¦ Çص¶Çϱâ À§ÇØ $Ran ¸Þ½îµå¸¦ Àû¿ëÇØ¾ß ÇÕ´Ï´Ù.¡¬n¡±;

      ### ¾ç¼ö 25000À¸·Î ·£´ý ¼ö¸¦ ¸¸µì´Ï´Ù.
    my $Ran = rand 25000;
    ($Ran, $Junk) = split(/¡¬./, $Ran, 2);
    $Ran = $Ran + 25000;

      ### ¿ì¸®°¡ ÀÚÁÖ »ç¿ëÇÏ°Ô µÉ ¼ö¿­À» ¸¸µì´Ï´Ù.
    my @Blank =  (1..$Ran);
      ### ¹è¿­À» °¡Á®¿Í¼­ ¹®ÀÚ¿­·Î ¸¸µì´Ï´Ù.
    my $Blank = ¡°@Blank¡±;
      ### ¸Þ¸ð¸®¸¦ ºñ¿ì±â À§ÇØ ¼öÀÇ ¹è¿­À» ºñ¿ó´Ï´Ù.
    @Blank = ();
    my $B_Length = length $Blank;

      ### ¿ì¸®°¡ ³ª´« °ø°£ÀÇ ÃѰ踦 ±¸ÇÕ´Ï´Ù.
    my @Temp = ¡®df¡¯;
    @Temp = grep($_ =~ /^$Partition/, @Temp);
    my $Line = $Temp[0];
    my ($Junk,$Blocks,@Junk) = split(/¡¬s+/, $Line,4);
      ### ºí·ÏÀ» 1k¶ó °¡Á¤ÇÕ´Ï´Ù.
    my $Size = $Blocks*1000;

      ## ¿ì¸®°¡ ¾´ ÆÄÀÏÀÌ ÆÄƼ¼Ç Å©±âº¸´Ù ÀÛÀ¸¸é °è¼ÓÇؼ­ ¹«¾ð°¡ µ¥ÀÌÅ͸¦ Ãâ·ÂÇÕ´Ï´Ù.
    while ($Written_Size < $Size)
      {
      $Count++;

            ### ¿­ ¹ø °¡¿îµ¥ ¾ÆÈ© ¹ø Á¤µµ´Â, Ãâ·Â ¼Óµµ¸¦ ³ôÀ̱â À§ÇØ ºó °ø°£À» Ãâ·ÂÇÕ´Ï´Ù.
            ### ¿­ ¹ø °¡¿îµ¥ ÇÑ ¹ø Á¤µµ´Â, ¾²·¹±â ¹ÙÀ̳ʸ®¸¦ Ãâ·ÂÇÕ´Ï´Ù.
         my $Ran = rand (10);
         if ($Ran > 1)
           {
           print FILE $Blank;
           $Written_Size = $Written_Size + $B_Length;
           }  
         else
           {
             ## ±ä ·£´ý µ¥ÀÌÅÍ ¹®ÀÚ¿­À» ¸¸µå´Â ºÎºÐÀÔ´Ï´Ù(10000 ¹ÙÀÌÃ÷ °¡±îÀÌ)
           my $Garbage = "";
           my $Length = rand(10000);
           ($Length, $Junk) = split(/¡¬./, $Length, 2);
           for (my $i = 0; $i < $Length; $i++)
             {
             my $Ran = rand 256;
             ($Ran, $Junk) = split(/¡¬./, $Ran, 2);
             $Garbage .= chr $Ran;
             }
             ## ÀÌ ºÎºÐ¿¡¼­´Â Çѹø¿¡ 8 ¹ÙÀÌÃ÷¾¿ ·£´ý µ¥ÀÌÅ͸¦ ¾ÏȣȭÇÕ´Ï´Ù.
           my $Temp = $Garbage;
           my $Encrypted = "";   

        while (length $Temp > 0)  
             {
             while (length $Temp < 8) {$Temp .= ¡°¡¬t¡±;}
             my $Temp2 = $Blowfish_Cipher->encrypt(substr($Temp,0,8));
             $Encrypted .= $Temp2;
             if (length $Temp > 8) {$Temp = substr($Temp,8);} else {$Temp = "";}
             }

             ### ¾ÏȣȭµÈ µ¥ÀÌÅ͸¦ ÆÄÀÏ¿¡ Ãâ·ÂÇÕ´Ï´Ù.
           print FILE $Encrypted;
           $Length = length $Encrypted;

           $Written_Size = $Written_Size + $Length;
           my $Rest = $Size - $Written_Size;
           print ¡°$Size - $Written_Size = $Rest to go¡¬n¡±;
           }

       ### 500 Ãâ·Â¸¶´Ù »õ ÆÄÀÏÀ» ÀúÀåÇϱ⠽ÃÀÛÇÕ´Ï´Ù.
      if ($Count =~ /500$/)
        {
        close FILE;
        open(FILE,¡°>>/tmp/WIPE_IT/$Count¡±);
        }
      }

    close FILE;
    #----------------------------------------------------

    my $Result = system (¡°umount $Partition¡±);
    #if ($Result > 0) {print ¡°Error unmounting partition $Partition, aborting.¡¬n¡±; exit; }
    if ($Result > 0) {print ¡°$Partition ÆÄƼ¼ÇÀ» ÇØÁ¦ÇÒ ¼ö ¾ø½À´Ï´Ù, ½ÇÇàÀ» Ãë¼ÒÇÕ´Ï´Ù.¡¬n¡±; exit; }

      ### ÆÄƼ¼ÇÀ» ´Ù½Ã Æ÷¸ËÇÕ´Ï´Ù. µ¥ÀÌÅÍ´Â »èÁ¦ÇÏÁö ¾Ê°í, µð·ºÅ͸®·ÎºÎÅÍ Áö¿ó´Ï´Ù.
    my $Result = system (¡°mkfs -t ext2 $Partition¡±);
    if ($Result > 0) {print ¡°Error making partition, aborting.¡¬n¡±; exit;}

    --------------------------------------------------------end of script

     

    ÀÌ ½ºÅ©¸³Æ® ¿ø¹®Àº http://linuxgazette.com/issue63/misc/nielsen2/Wipe_It.pl.txt¿¡ ÀÖ½À´Ï´Ù.

 

¸ÎÀ½

    ²À Expect¸¦ »ç¿ëÇØ¾ß ÇÏ´Â °ÍÀº ¾Æ´Õ´Ï´Ù. (´Ù¸¥ ÇÁ·Î±×·¥µéÀº ³»°¡ ¾î·Æ°Ô ó¸®ÇÑ ¹®Á¦µéÀ» °£´ÜÇÏ°Ô ÇØ°áÇÒ ¼ö ÀÖ¾ú½À´Ï´Ù). Blowfish ¿ª½Ã ¹Ýµå½Ã »ç¿ëÇØ¾ß ÇÏ´Â °ÍÀº ¾Æ´Õ´Ï´Ù. »ç½Ç, ÀÌ·¸°Ô Â¥Áý±âÇÑ ½ºÅ©¸³Æ® Àüü´Â, ¿©·¯ºÐÀÌ ´ÜÁö ÇÏµå µå¶óÀ̺긦 Áö¿ì°í ±× ¼ÓÀ» ºñ¿ö³»·Á°í¸¸ ÇÑ´Ù¸é ³Ê¹« ±ä ¹æ¹ýÀÔ´Ï´Ù. ±×·¸±â´Â Çصµ, ³ª´Â ´Ã fdisk¸¦ »ç¿ëÇϹǷÎ, ÀÌ ½ºÅ©¸³Æ®¿¡¼­µµ ¿ª½Ã fdisk¸¦ »ç¿ëÇß½À´Ï´Ù. ¶Ç, Expect´Â ¸Å¿ì °­·ÂÇÑ µµ±¸¿©¼­, ¾î¶»°Ô µ¿ÀÛÇÏ´ÂÁö ¾Ë¾Æº¸´Â °Íµµ À¯ÀÍÇÑ ÀÏÀÔ´Ï´Ù. ±×¸®°í, ¸¶±¸ÀâÀÌ·Î ¾ÏȣȭµÈ ¾²·¹±â ¹ÙÀ̳ʸ® µ¥ÀÌÅ͸¦ Áý¾î ³Ö´Â ÀÏÀº ÇØÄ¿µéÀ» ³î¸®±â À§ÇØ ±×³É Çѹø Çغ» °ÍÀÔ´Ï´Ù.(¿ª½Ã ²À ÇÊ¿äÇÑ °ÍÀº ¾Æ´Õ´Ï´Ù)

    ³ª´Â ÇÏµå µå¶óÀ̺êÀÇ º¹ÀâÇÑ ¿ø¸®¿¡ ´ëÇØ ¿ÏÀüÇÏ°Ô ÀÌÇØÇÏÁö´Â ¸øÇϹǷÎ, ÇÏµå µå¶óÀ̺꿡 µ¥ÀÌÅÍ Â±â°¡ ³²´Â´Ù¸é ¾È½ÉÇÒ ¼ö°¡ ¾ø½À´Ï´Ù. ³»°¡ ÇÏ·Á´Â ÀÏ¿¡, ±×¸®°í ³»°Ô ÇÊ¿äÇÑ º¸¾È ¼öÁØ¿¡, ÀÌ ½ºÅ©¸³Æ®´Â µü ¸Â´Â ÀÏÀ» ÇÕ´Ï´Ù. ³»°¡ MILAS¸¦ ´õ °³¹ßÇÔ¿¡ µû¶ó, ´õ ²Ä²ÄÇÏ°Ô Á¡°ËÇؼ­ ÇÏµå µå¶óÀÌºê ¾È¿¡ µé¾î ÀÖ´Â ¸ðµç µ¥ÀÌÅ͸¦ Áö¿ì´Â ¹æ¹ýµéÀ» °­È­ÇÒ °ÍÀ̶ó°í È®½ÅÇÕ´Ï´Ù.

    ³ª´Â ¹Ì·¡¿¡ ÇÊ¿äÇÏ°Ô µÉÁöµµ ¸ð¸£´Â ÀϵéÀ» ¹Ì¸® ¿¹»óÇÏ¿©, Ç×»ó ÇÁ·Î±×·¡¸ÓµéÀÌ °¡±î¿î ÇÁ·ÎÁ§Æ®¿¡ ÇÊ¿äÇÑ °Íµéº¸´Ù ´õ ¸¹Àº ÀÏÀ» ÇÏ°Ô ¸¸µå´Â °æÇâÀÌ ÀÖ½À´Ï´Ù. ¾Æ¹«Æ° ÀÌ¹Ì ±×·¸°Ô µÇ¾î¹ö·È°í, ³ª´Â ½ºÅ©¸³Æ® ÁøÇà ¹æÇâÀÌ ¸¶À½¿¡ µì´Ï´Ù. ±×¸®°í, ±×·¸°Ô ÀÌ ±â»ç¸¦ ¾²´Â °ÍÀº ºñÇà±â ¿©ÇàÀ» Áö°ãÁö ¾Ê°Ô ÇØÁÝ´Ï´Ù. ´©±º°¡¸¦ À§ÇØ ÀÏÇØ¾ß ÇÏ´Â °Í°ú´Â ´Ù¸£°Ô ¹«¾ð°¡ ½Å³ª´Â °ÍÀ» ¸¸µé ¶§¿¡´Â ÁöÄ¡Áö ¾Ê½À´Ï´Ù. ±×·±°Ô ÁøÂ¥ ÀÏÀÔ´Ï´Ù.

 

Âü°í

    Perl.com À¥»çÀÌÆ® - http://www.perl.com/

    Expect Perl Module -
            http://www.perl.com/CPAN-local/modules/by-category/ ¡¬
            21_File_Handle_Input_Output/Expect /Expect-1.10.readme

    Blowfish Perl Module -
            http://www.perl.com/CPAN-local/modules/by-category/ ¡¬
           14_Security_and_Encryption/Crypt /Crypt-Blowfish-2.06.readme

    ÀÌ ±â»çÀÇ ¿ø·¡ »çÀÌÆ® -
            http://www.gnujobs.com/Articles/14/Wipe_It.html
            (±â»ç°¡ ¾÷µ¥ÀÌÆ®µÇ¸é ÀÌ »çÀÌÆ®¿¡ µÓ´Ï´Ù)

    µð½ºÅ©¿¡ ³»¿ëÀ» µ¤¾î¾µ ¶§ /dev/randomÀ̳ª /dev/urandomÀ» »ç¿ëÇÒ ¼öµµ ÀÖ½À´Ï´Ù. Answer GangÀ» º¸¼¼¿ä: 60ȸ¿¡ ½Ç¸° ¡°Classified Disk - Low-level Format¡±, ±×·¯³ª ÀÌ ±â»ç´Â ¾ÏȣȭÇÏÁö´Â ¾Ê½À´Ï´Ù. - http://linuxgazette.com/issue60/lg_answer60.html#tag/9

 

Copyright

    ---------------------------------------------------------
    Copyright ¨Ï 2001, Mark Nielsen.
    Copying license http://www.linuxgazette.com/copying.html
    Published in Issue 63 of Linux Gazette, Mid-February (EXTRA) 2001




¡ã top

homeÀ¸·Î...