challenge ACLの制御

通常、作成者以外は、読み書きができないファイルを新規作成してください。
# UNIX的にいうと「0600」のファイルです。

すでに存在していた場合、新しい内容で上書きしてください。

symlinkアタック等を考慮する必要はありません。

余裕のある人はファイルがすでに存在していた場合、
パーミッションを変更してみてください。

Posted feedbacks - C#

.NET Framework限定 (Monoでは動きそうにない)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;

class P
{
  static void Main(string[] args)
  {
    if (args.Length == 0) return;
    using (Stream s = File.Open
      (args[0],
      FileMode.CreateNew,
      FileAccess.Write,
      FileShare.ReadWrite))
    {
      FileSecurity sec = File.GetAccessControl(args[0]);
      IdentityReference owner = sec.GetOwner(typeof(NTAccount));
      sec.SetAccessRuleProtection(true, false);
      foreach (AuthorizationRule r
        in sec.GetAccessRules(true, true, typeof(NTAccount)))
      {
        sec.RemoveAccessRule((FileSystemAccessRule)r);
      }
      sec.AddAccessRule
        (new FileSystemAccessRule
          (owner,
          FileSystemRights.Read | FileSystemRights.Write,
          AccessControlType.Allow));
      File.SetAccessControl(args[0], sec);
    }
  }
}

Index

Feed

Other

Link

Pathtraq

loading...