การทำ /tmp ให้ ไม่สามารถ execue ได้

คือมีการบอกว่า ควรทำให้ /tmp ไม่สามารถ เรียก พวก file excuse ได้
แต่ partition ของ server ผมมันเป็นก้อน เดียวกันแบบนี้
จะสามารถแก้ได้ไหมครับ

[root@ns root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda3 71G 11G 57G 16% /
/dev/hda1 99M 8.2M 86M 9% /boot
none 500M 0 500M 0% /dev/shm

จะมีการแก้ เหมือนพวก partition magic แบบไม่กระทบ ต้อง เครื่องที่ทำงานอยู่ไหม

ลองอ่านดูที่


http://www.crucialp.com/resources/tutorials/dedicated-server/securing-tmp-partition-cpanel-whm.php

คือไม่ทราบว่า มันสามารถใช้ กับ เครือ่งที่ลงไว้เรียบร้อยแล้ว ด้วยใช่ไหมครับ
( อย่างของผม เหมือนว่า คนลง ระบบเค้าจะรวม ทุกอย่างใน partition เดียวเลย)

[root@host root]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda3 73568972 20709252 49062356 30% /
/dev/hda1 101089 8341 87529 9% /boot
none 252872 5232 247640 3% /dev/shm

ใช่ครับ

[root@host root]# cd /dev
[root@host dev]# dd if=/dev/zero of=tmpMnt bs=1024 count=100000
100000+0 records in
100000+0 records out
[root@host dev]# /sbin/mke2fs /dev/tmpMnt
mke2fs 1.34 (25-Jul-2003)
/dev/tmpMnt is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
25064 inodes, 100000 blocks
5000 blocks (5.00%) reserved for the super user
First data block=1
13 block groups
8192 blocks per group, 8192 fragments per group
1928 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@host dev]# cd /
[root@host /]# cp -R /tmp /tmp_backup
[root@host /]# mount -o loop,noexec,nosuid,rw /dev/tmpMnt /tmp
[root@host /]# chmod 0777 /tmp
[root@host /]# cp -R /tmp_backup/* /tmp/
[root@host /]# rm -rf /tmp_backup

[root@host tmp]# cat /etc/fstab
/dev/hda3 / ext3 defaults,usrquota 11
/dev/hda1 /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
/dev/hda2 swap swap defaults 0 0
/dev/tmpMnt /tmp ext2 loop,noexec,nosuid,rw 0 0

[root@host tmp]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda3 73568972 4464832 65306776 7% /
/dev/hda1 101089 8341 87529 9% /boot
none 224916 0 224916 0% /dev/shm
/dev/tmpMnt 96828 17 91811 1% /tmp

ไม่รู้ว่า แบบนี้ ถูกไหมครับ จะมี การทดลองได้อย่างไรดีครับ ว่าทำสำเร็จ หรือ ถูกต้องหรือเปล่า

ลองเข้าไปใน folder นั้นดูแล้วสั่ง execute script ที่อยู่ในนั้นครับ

script ง่ายๆ

vi /tmp/test.sh

#!/bin/sh
echo "Hello world

chmod a+x test.sh
/tmp/test.sh

ถ้ารันได้ก็แสดงว่าไม่ปลอดภัย

[root@host tmp]# chmod a+x test.sh
[root@host tmp]# /tmp/test.sh
-bash: /tmp/test.sh: /bin/sh: bad interpreter: Permission denied

ผ่านไหมคัรบ :slight_smile:

ให้ชัวร์ลองตัวนี้ดีกว่า ตะกี้ผมเขียน code ผิด (เครื่องหมายฟันหนูหายไปตัวนึง)

#!/bin/sh
echo “Hello world”

หลังทำแล้วเหมือน error เพียบเลยนะครับ
กับทั้ง horde และ พวก smf หรือ invision board
ไม่รู้เกียวกับ permission หรือเปล่าครับ
drwxr-xr-x 4 root root 1024 Sep 27 04:02 tmp
drwxrwxrwt 6 root root 4096 Sep 26 23:30 tmp_backup

tmp_backup เป็นอันของเก่าที่เก็บไว้ก่อน

Warning: Unknown(): open(/tmp/sess_226f67c958a014a82e8445dadb10c22f, O_RDWR) failed: Permission denied (13) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0

mySQL error: Can’t create/write to file ‘/tmp/#sqlff6_15939_0.MYI’ (Errcode: 13)
mySQL error code:

ถ้า smf มันขึ้น
Please try again. If you come back to this error screen, report the error to an administrator.

chmod 777 /tmp

ครับ

ขั้นตอน copy มันทำให้ permission เสีย

chmod +t /tmp

ด้วยครับ

Edit: ชี้แจงเพิ่มเติม t คือ sticky bit แปลว่า ไฟล์ฺต่างๆใน /tmp จะสามารถถูก rename & rm ได้โดย file owner หรือ root หรือเจ้าของ directory /tmp (ซึ่งปกติก็คือ root) เท่านั้น

แบบสั้นๆ สามารถ

chmod 1777 /tmp

ได้เลยครับ