chmod etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
chmod etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

3 Kasım 2021 Çarşamba

chmod komutu ve Kullanılabilecek Gruplar

Giriş
Gruplar şöyledir.
u, for the owner
g, for the group
o, for others
a, for all, which can also be written as ugo.
chmod komutunu kullanırken komutun hangi gruplara uygulanacağını belirtebiliriz. Eğer belirtmezsek sanırım umask ayarımız devreye giriyor

Kullanım şöyle
chmod grouplar (+ veya eksi veya = karakteri başlayan permission) (dosya ismi)
Permission için açıklama şöyle
  • If we want to give permissions to a set of users or user, we write +, so +x will give execute permission and +rx will give read and execute permission.
  • If we want to revoke permissions, we write -, so -rwx takes away read, write, and execute access.
  • If we want to replace permissions entirely, we use =, so =r will give read access, but remove execute and write if they existed. Similarly, =rw is the same as read and write access, with execute removed if it existed.
Örnek - u
Şöyle yaparız
chmod u+r file.txt
Örnek - u
Şöyle yaparız. ugo yerine all da kullanılabilir.
chmod ugo+rw file.txt
Örnek - u
Şöyle yaparız. user'a rwx verir geri kalan hakları kaldırır. group'a rw verir geri kalan hakları kaldırır. owner'a r verir geri kalan hakları kaldırır
chmod u=rwx,g=rw,o=r file.txt

Örnek - a Yani All Anlamına Gelir
Şöyle yaparız
To set all the bits, ignoring umask, you need to specify who you want to set them for:

chmod a+rwx file

or more explicitly,

chmod ugo+rwx file
Örnek - Gruplar İçin Ayrı Ayrı
755'i vermek için harfleri kullanarak şöyle yaparız
chmod -R u=rwx,g=rx,o=rx folder
Örnek - MyGroup ve Owner
secret dizinindeki group ve owner için hakları almak için şöyle yaparız
chmod -R g=,o= secret

22 Temmuz 2021 Perşembe

chmod gid bit - Dosya Paylaşmak İçindir

Giriş
Açıklaması şöyle. Dizin için kullanılırsa, dizinde dosya oluşturulunca sahibinin grubuna değil, dizinin grubuna ait olur
chmod preserves a directory's set-user-ID and set-group-ID bits unless you explicitly specify otherwise. You can set or clear the bits with symbolic modes like u+s and g-s, and you can set (but not clear) the bits with a numeric mode.
Örnek - grup hakkı vermek
Gruba guid hakkı vermek için şöyle yaparız.
chmod g+s [path]
Örnek - grup hakkını almak
Şöyle yaparız.
% stat -c '%04a' ~/testdir
2700

% chmod g-w ~/testdir
% stat -c '%04a' ~/testdir
0700
Örnek - grup hakkı vermek
Elimizde bir grup olsun ve buna kullanıcıları ekleyelim
addgroup webimage

adduser user1 webimage
adduser user2 webimage
adduser www-data webimage
Gruptaki herkese yazma hakkı vermek için şöyle yaparız
sudo chmod g+s image/
Açıklaması şöyle
This will cause any file created in that directory to be owned by the same group as the directory. Thus, if image is owned by group webimage, any file created there will be owned by the group webimage. If also read and write permissions are set for the group, all members of the group will be able to update the file.

16 Aralık 2019 Pazartesi

chmod suid Biti - Dosya Sahibinin Hakları İle Çalıştırılır

Giriş
Genellikle bir uygulamayı root olarak çalıştırmak için kullanılır

suid Yerine Diğer Seçenekler

1. Capability Kullanımı
Açıklaması şöyle.
From my understanding the trend these last years has been to remove setuid binaries and replaced them with capabilities.
Örneğin ping için raw socket açmak gerekir. Bunun için de ya root access ya da cap_net_raw capability gerekir. setcap komutu yazısına bakabilirsiniz.

2. Kernel Ayarları 
/etc/sysctl.conf Dosyası yazısına bakabilirsiniz
sysctl komutu yazısına bakabilirsiniz.

suid Nedir
suid - Set User ID - anlamına gelir. suid biti dosyalarda kullanılır, dizinlerde bir etkisi yoktur. Açıklaması şöyle.
So if the file is owned by root and the SUID bit is turned on, the program will run as root. Even if you execute it as a regular user. The same thing applies to the GUID bit.
SUID Zararlı Mıdır ?
Açıklaması şöyle.
A SUID binary is not inherently exploitable for privilege escalation. The problem is when there is a vulnerability in the software or an administrator sets the SUID bit on a binary that should not have it set. An extreme example of the latter would be an admin setting vim to SUID with owner root, allowing users to execute bash commands as root within a vim session (:![shell command]).
Ping suid bitine ihityaç duyar. Açıklaması şöyle.
The ping utility requires the binary to be owned by root and the SUID bit set because it sends/receives ICMP requests using "raw sockets" which only root can do.
Nasıl Yaparız
rwx bitlerindeki x'in yerine s veya S gelir. Açıklaması şöyle.
chmod preserves a directory's set-user-ID and set-group-ID bits unless you explicitly specify otherwise. You can set or clear the bits with symbolic modes like u+s and g-s, and you can set (but not clear) the bits with a numeric mode.
Örnek - Etkinleştirmek
Şöyle yaparız. 4 sayısı u+s anlamına gelir.
chmod 4755 file
Örnek - Kaldırmak
Şöyle yaparız. En başa 0 konulur
chmod 0554 /bin/passwd

22 Ekim 2019 Salı

chmod ve sticky bit - Dizinde Herkes Dosya Oluşturabilir Ancak Sadece Dizin Sahibi Silebilir

sticky bit
sticky biti genellikle dizinlerde kullanılır. ls komutu ile bakılınca dizin t veya T ile gösteriliyorsa sticky biti atanmış anlamına gelir.

Dizine Uygulamak
Açıklaması şöyle. Bir dizinde herkes dosya oluşturabilir ancak sadece dosyanın sahibi silebilir.
That is, the sticky bit's presence on a directory only allows contained files to be renamed or deleted if the user is either the file's owner or the containing directory's owner (or the user is root).
Bu bit genellikle /tmp dizininde kullanılır. Böylece bu dizinde herkes kendi dosyasını oluşturabilir ancak başkasının dosyasını silemez. Açıklaması şöyle.
For directories, it prevents unprivileged users from removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp.
Örnek
Şöyle yaparız. ls komutunun çıktısında t harfi görülebilir.
# chmod 1777 directory
# ls -ld directory
drwxrwxrwt  2 root  wheel  2 Oct 21 17:06 directory/
Örnek
Şöyle yaparız. user ve group ve owner'a yazma hakkı verir. Ayrıca sticky bit'i de atar.
# chmod ugo+w,+t directory
Dosyaya Uygulamak
Dosyalarda da uygulanabilir. Açıklaması şöyle. Ancak günümüzde bir işlevi olup olmadığını bilmiyorum.
The sticky bit was originally used for a completely different purpose: if it was set on an executable file, it told the operating system to retain the text segment in swap. Thus the name "Sticky Bit".

28 Mayıs 2019 Salı

chmod komutu - Dosya Ve Dizinlerin Haklarını Değiştirir

Giriş
chmod sadece dosya sahibi veya root tarafından izinleri değiştirmek için kullanılabilir.
Of course, only the owner of a file may use chmod to alter a file's permissions
chmod ile kullanılan sayıların anlamı şöyledir.
0 no permission
1 execute
2 write
3 execute + write
4 read 
5 read + execute
6 read + write
7 all
Gruplar şöyledir.
u - Owner
g - group
o - others
Grupların belirtilerek hakların tanımlanması için chmod komutu ve Gruplar yazısına bakınız

Bazı Sabitler
Bu sabitler man 2 chmod ile görülebilir. S_I "stat inode" anlamına gelir.

Şöyledir
S_IRUSR  (00400)  read by owner
S_IWUSR  (00200)  write by owner
S_IXUSR  (00100)  execute/search  by owner ("search" applies for direc-
                     tories, and means that entries within  the  directory
                     can be accessed)
S_IRGRP  (00040)  read by group
S_IWGRP  (00020)  write by group
S_IXGRP  (00010)  execute/search by group
S_IROTH  (00004)  read by others
S_IWOTH  (00002)  write by others
S_IXOTH  (00001)  execute/search by others
suid, guid ve sticky bitler için sabitler şöyledir.
S_ISUID  (04000)  set-user-ID  (set  process  effective  user   ID   on
                  execve(2))

S_ISGID  (02000)  set-group-ID  (set  process  effective  group  ID  on
                  execve(2);  mandatory  locking,   as   described   in
                  fcntl(2);  take a new file's group from parent direc-
                  tory, as described in chown(2) and mkdir(2))

S_ISVTX  (01000)  sticky bit (restricted deletion flag, as described in
                  unlink(2))
Örnek
Sayı vererek şöyle yaparız.
chmod 777 myapp
Dizin İçin Haklar
Açıklaması şöyle.
For a directory, "read" access lets you list the contents, and "execute" access lets your traverse the directory to open one of its children (file or subdirectory). So if you remove:

-just the read access, people can still access subdirectories by guessing their names
-just the execute flag, people can still list the names of the contents even if they cannot access them, and this can still be revealing
-both read and execute privileges on a directory, anything below it becomes unreachable, and you don't need to make a recursive change.
Eğer Tüm Haklar 0 İse
Elimizde şöyle bir dosya olsun
---------- myFile.txt
root bu dosyayı okuyabilir ve dosyaya yazabilir ancak çalıştıramaz.

Çalıştırabilmesi için en az bir grubun x (execute) hakkına sahip olması gerekir. Yani şöyle olmalıdır.
---x------ myFile.txt
veya
------x--- myFile.txt
veya
---------x myFile.txt
Hakları Geri Almak
Açıklaması şöyle. Eksi işareti ile hak geri alınır.
The operator + causes the selected file mode bits to be added to the existing file mode bits of each file; - causes them to be removed; and = causes them to be added and causes unmentioned bits to be removed except that a directory's unmentioned set user and group ID bits are not affected.
Örnek
Şöyle yaparız.
chmod -664 my_file
execute hakkı - (x harfi)
Dizinlere girebilmek için read değil için execute hakkının olması gerekir. Dizinler için genellikle,777 (herkes erişebilir) 750 (sahip ve grup erişebilir) veya 700 (sadece sahip erişebilir) hakkı verilir.

Örnek
Kullanıcıya execute hakkı vermek için şöyle yaparız.
chmod u+x myfolder
Örnek
Herkese execute hakkı vermek için şöyle yaparız.
sudo chmod a+x your_program
Örnek
Herkesten execute hakkını kaldırmak için şöyle yaparız.
chmod a-x /path/to/program
read hakkı - (r harfi)
Örnek
user,group ve owner'dan read hakkını recursive olarak almak için şöyle yaparız
chmod -R ugo-r [path]
write hakkı - (w harfi)
Örnek
Gruba yazma hakkı vermek için şöyle yaparız.
chmod g+w [path]
sticky bit -  Bir dizinde herkes dosya oluşturabilir ancak sadece dosyanın sahibi silebilir.
sticky bit yazısına taşıdım.

suid bit - Dosya Sahibinin Hakları İle Çalıştırılır
suid bit yazısına taşıdım.

guid bit - Dizinde Gruba Ait Herkes Dosya Oluşturabilir
guid bit yazısına taşıdım

Örnek - user
Şöyle yaparız. 4 sayısı u+s anlamına gelir.
chmod 4755 file
-R seçeneği
Recursive çalışır. Şöyle yaparız.
# Give read access to everyone
chmod -R a+r folder